forked from salarcode/SmartProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
72 lines (65 loc) · 2.17 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const path = require('path');
const decompress = require('decompress');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
if (process.env.NODE_ENV == null) {
process.env.NODE_ENV = 'development';
}
const ENV = process.env.ENV = process.env.NODE_ENV;
let plugins = [
new CleanWebpackPlugin([
path.resolve(__dirname, 'build/*'),
]),
new CopyWebpackPlugin([
{ from: './src/_locales/', to: '_locales', ignore: ['default-messages.json'], },
{ from: './src/icons', to: 'icons' },
{ from: './src/ui', to: 'ui', ignore: ['code/*', '*.zip'] },
])
];
const unzipPromise = decompress('src/ui/js/libs-unzip-before-build.zip', 'src/ui/js/');
module.exports = function (args) {
let browserType = args["browser"] || "chrome";
let isDev = args["dev"] || false;
let coreIsServiceWorker = args["service_worker"] || false;
plugins.push(new CopyWebpackPlugin([{ from: `./src/manifest-${browserType}.json`, to: 'manifest.json' }]));
let codeEntries = {
'core': [],
'ui/code/popup': ['./src/ui/code/popup.ts', `./src/core/browsers/${browserType}.ts`],
'ui/code/proxyable': ['./src/ui/code/proxyable.ts', `./src/core/browsers/${browserType}.ts`],
'ui/code/settingsPage': ['./src/ui/code/settingsPage.ts', `./src/core/browsers/${browserType}.ts`],
};
if (coreIsServiceWorker) {
codeEntries["core"] = [`./src/core/browsers/${browserType}.ts`, './src/core/ServiceWorker/CoreServiceWorker.ts']
}
else {
codeEntries["core"] = [`./src/core/browsers/${browserType}.ts`, './src/core/Core.ts',]
}
return unzipPromise.then(() => {
return {
mode: ENV,
entry: codeEntries,
devtool: '',
// devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.ts', '.js']
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'build' + (isDev ? '-' + browserType : '')),
},
optimization: {
minimize: !isDev
},
plugins: plugins
}
});
};