This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
/
webpack.config.js
92 lines (89 loc) · 2.05 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
91
92
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
if (!process.env.TARGET) {
throw Error("Please specify env var TARGET, 'chrome', 'firefox' or 'opera'.");
} else if (
!(
process.env.TARGET === 'chrome' ||
process.env.TARGET === 'firefox' ||
process.env.TARGET === 'opera' ||
process.env.TARGET === 'edge'
)
) {
throw Error("TARGET can only be 'chrome', 'firefox', 'opera' or 'edge'.");
} else {
console.info(`\x1b[1;32mBuilding for ${process.env.TARGET}...\x1b[m`);
}
module.exports = {
context: path.resolve(__dirname, 'src'),
devtool: 'cheap-module-source-map',
entry: {
'./popup/popup': './popup/popup.js',
'./options/options': './options/options.js',
},
output: {
path: path.resolve(__dirname, 'dist', process.env.TARGET),
filename: '[name].js',
},
node: {
global: false,
},
plugins: [
new CopyPlugin([
{
from: `./manifest.${process.env.TARGET}.json`,
to: './manifest.json',
},
{
from: './icons/*',
to: './icons',
flatten: true,
},
{
from: './options/*',
to: './options/',
flatten: true,
ignore: ['*.js', '*.html'],
},
{
from: './popup/*',
to: './popup/',
flatten: true,
ignore: ['*.js'],
},
{
from: './popup/vendors/js/*',
to: './popup/vendors/js/',
flatten: true,
},
{
from: './popup/img/*',
to: './popup/img/',
flatten: true,
},
]),
new webpack.DefinePlugin({
global: 'window', // Placeholder for global used in any node_modules
}),
],
};
if (process.env.TARGET === 'edge') {
module.exports.plugins.push(
new CopyPlugin([
{
from: './options/options.edge.html',
to: './options/options.html',
},
]),
);
} else {
module.exports.plugins.push(
new CopyPlugin([
{
from: './options/options.html',
to: './options/options.html',
},
]),
);
}