/* [note] modified from github.com/microsoft/vscode-pull-request-github MIT licenced*/

const path = require('path');
const webpack = require('webpack');

function getWebviewConfig(env) {
	let webview = {
		name: 'webview',
		mode: env.production ? 'production' : 'development',
		entry: {
			index: './infoview/index.tsx'
		},
		module: {
			rules: [
				{
					test: /\.tsx?$/,
					use: 'ts-loader',
					exclude: /node_modules/
				},
				{
					test: /\.css/,
					use: ['style-loader', 'css-loader']
				},
				{
					test: /\.svg/,
					use: ['svg-loader']
				}
			]
		},
		resolve: {
			extensions: ['.tsx', '.ts', '.js', '.svg']
		},
		devtool: !env.production ? 'inline-source-map' : undefined,
		output: {
			filename: '[name].js',
			path: path.resolve(__dirname, 'media')
		},
		plugins: [
			new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
		]
	};

	return webview;
}

function getExtensionConfig(env) {
	let config = {
		name: 'extension',
		mode: env.production ? 'production' : 'development',
		target: 'node',
		entry: {
			extension: './src/extension.ts'
		},
		module: {
			rules: [
				{
					test: /\.tsx?$/,
					use: 'ts-loader',
					exclude: /node_modules/
				}
			]
		},
		resolve: {
			extensions: ['.tsx', '.ts', '.js'],
			alias: {
				"node-fetch": path.resolve(__dirname, 'node_modules/node-fetch/lib/index.js'),
			}
		},
		devtool: !env.production ? 'source-map' : undefined,
		output: {
			filename: '[name].js',
			path: path.resolve(__dirname, 'out'),
			libraryTarget: "commonjs",
			devtoolModuleFilenameTemplate: 'file:///[absolute-resource-path]'
		},
		externals: {
			'vscode': 'commonjs vscode'
		}
	};
	return config;
}

module.exports =  function(env) {
	env = env || {};
	env.production = !!env.production;
	return [getWebviewConfig(env), getExtensionConfig(env)];
};
@@ -473,22 +473,930 @@
 e: %5B
-'style-loader'
+%7B%0A%09%09%09%09%09%09loader: 'style-loader',%0A%09%09%09%09%09%09options: %7B%0A%09%09%09%09%09%09%09// copied from https://webpack.js.org/loaders/style-loader/#insert%0A%09%09%09%09%09%09%09// makes sure that the styles are inserted at the top of the head object instead of the default behaviour at the bottom.%0A%09%09%09%09%09%09%09insert: function insertAtTop(element) %7B%0A%09%09%09%09%09%09%09%09var parent = document.querySelector('head');%0A%09%09%09%09%09%09%09%09// eslint-disable-next-line no-underscore-dangle%0A%09%09%09%09%09%09%09%09var lastInsertedElement =%0A%09%09%09%09%09%09%09%09%09window._lastElementInsertedByStyleLoader;%0A%0A%09%09%09%09%09%09%09%09if (!lastInsertedElement) %7B%0A%09%09%09%09%09%09%09%09%09parent.insertBefore(element, parent.firstChild);%0A%09%09%09%09%09%09%09%09%7D else if (lastInsertedElement.nextSibling) %7B%0A%09%09%09%09%09%09%09%09%09parent.insertBefore(element, lastInsertedElement.nextSibling);%0A%09%09%09%09%09%09%09%09%7D else %7B%0A%09%09%09%09%09%09%09%09%09parent.appendChild(element);%0A%09%09%09%09%09%09%09%09%7D%0A%0A%09%09%09%09%09%09%09%09// eslint-disable-next-line no-underscore-dangle%0A%09%09%09%09%09%09%09%09window._lastElementInsertedByStyleLoader = element;%0A%09%09%09%09%09%09%09%7D,%0A%09%09%09%09%09%09%7D,%0A%09%09%09%09%09%7D
 , 'c
@@ -2590,17 +2590,16 @@
 xports =
- 
  functio
@@ -2599,16 +2599,17 @@
 function
+ 
 (env) %7B%0A

Make style-loader insert at top of head.