forked from salarcode/SmartProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
90 lines (82 loc) · 2.43 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const path = require('path');
const decompress = require('decompress');
const CopyPlugin = 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({
cleanAfterEveryBuildPatterns: ['**/*.LICENSE.txt'],
protectWebpackAssets: false
}),
new CopyPlugin({
patterns: [
{
from: './src/_locales/', to: '_locales',
globOptions: {
ignore: ['**/default-messages.json']
}
},
{ from: './src/icons', to: 'icons' },
{
from: './src/ui', to: 'ui',
globOptions: {
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 CopyPlugin({
patterns: [
{ 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',]
}
console.info("Building for", browserType, 'isDev=' + isDev);
return unzipPromise.then(() => {
return {
mode: ENV,
entry: codeEntries,
devtool: isDev ? 'inline-source-map' : false,
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
}
});
};