This repository was archived by the owner on Oct 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.bundle.js
More file actions
112 lines (98 loc) · 3.02 KB
/
webpack.bundle.js
File metadata and controls
112 lines (98 loc) · 3.02 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const {DefinePlugin, BannerPlugin} = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const path = require('path');
const fs = require('fs');
const defineScripts = require('./builder/defineScripts');
const getDistPath = require('./builder/getDistPath');
const getBackgroundScripts = require('./builder/getBackgroundScripts');
const getContentScripts = require('./builder/getContentScripts');
const getLocaleMap = require('./builder/getLocaleMap');
const getOptions = require('./builder/getOptions');
const getPopup = require('./builder/getPopup');
const mode = BUILD_ENV.mode;
const browser = BUILD_ENV.monoBrowser;
const monoPath = BUILD_ENV.monoPath;
const distPath = getDistPath();
const {LOCALE_MAP, DEFAULT_LOCALE} = getLocaleMap();
const BACKGROUND_SCRIPTS = getBackgroundScripts();
const {OPTIONS_SCRIPTS, OPTIONS_PAGE} = getOptions();
const {POPUP_SCRIPTS, POPUP_PAGE} = getPopup();
const {CONTENT_SCRIPT_MAP, CONTENT_SCRIPT_INDEX, CONTENT_SCRIPTS} = getContentScripts();
const meta = String(fs.readFileSync(path.join(distPath, `./meta.txt`)));
const jsRulesUseArray = [];
const config = {
entry: {
bundle: 'bundle',
},
output: {
path: distPath,
filename: '[name].js'
},
mode: mode,
devtool: 'none',
module: {
rules: [
{
test: /\.js$/,
enforce: 'pre',
exclude: /node_modules/,
use: [{
loader: 'babel-loader',
options: {
plugins: [
[require('./builder/babel-plugin-define'), {
BACKGROUND_SCRIPTS: defineScripts(BACKGROUND_SCRIPTS),
OPTIONS_PAGE: JSON.stringify(OPTIONS_PAGE),
OPTIONS_SCRIPTS: defineScripts(OPTIONS_SCRIPTS),
POPUP_PAGE: JSON.stringify(POPUP_PAGE),
POPUP_SCRIPTS: defineScripts(POPUP_SCRIPTS),
CONTENT_SCRIPTS: JSON.stringify(CONTENT_SCRIPTS),
CONTENT_SCRIPT_MAP: JSON.stringify(CONTENT_SCRIPT_MAP),
CONTENT_SCRIPT_INDEX: defineScripts(CONTENT_SCRIPT_INDEX),
}]
],
}
}]
},
{
test: /\.js$/,
exclude: /node_modules/,
use: jsRulesUseArray
},
]
},
resolve: {
alias: {
'bundle': path.join(monoPath, `./browsers/${browser}/bundle`),
}
},
plugins: [
new CleanWebpackPlugin([
path.join(distPath, 'includes'),
path.join(distPath, 'js'),
path.join(distPath, 'options.html'),
path.join(distPath, 'popup.html'),
path.join(distPath, '_locales'),
path.join(distPath, 'manifest.json'),
]),
new BannerPlugin({
banner: meta,
raw: true,
entryOnly: true
}),
new DefinePlugin({
DEFAULT_LOCALE: JSON.stringify(DEFAULT_LOCALE),
LOCALE_MAP: JSON.stringify(LOCALE_MAP),
'process.env': {
DEBUG: JSON.stringify('*'),
},
})
],
};
if (BUILD_ENV.babelOptions) {
jsRulesUseArray.push({
loader: 'babel-loader',
options: BUILD_ENV.babelOptions
});
}
module.exports = config;