-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
78 lines (72 loc) · 2.28 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
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const ExtensionReloader = require('webpack-extension-reloader');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const { version } = require('./package.json');
const DIST = path.resolve(__dirname, './dist');
const RESOURCES = path.resolve(__dirname, './resources');
const SRC_BACKGROUND = path.resolve(__dirname, './src/background');
const SRC_CONTENT = path.resolve(__dirname, './src/content');
const MANIFEST = path.resolve(RESOURCES, './manifest.json');
const ICONS = path.resolve(RESOURCES, './icons');
const getBaseConfig = (production) => ({
mode: production ? 'production' : 'development',
devtool: production ? false : 'inline-cheap-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
}
});
module.exports = ({ production = false, reloader = false, analyze = false } = {}) => {
const config = {
...getBaseConfig(production),
entry: {
background: SRC_BACKGROUND,
content: SRC_CONTENT
},
output: {
filename: '[name].js',
path: DIST
},
plugins: [
new CopyPlugin([
{
from: MANIFEST,
to: DIST,
transform: (content) => {
const manifest = JSON.parse(content.toString());
manifest.version = version;
return JSON.stringify(manifest, undefined, 4);
}
},
{
from: ICONS,
to: path.resolve(DIST, './icons')
}
])
]
};
if (reloader) {
config.plugins.push(
new ExtensionReloader({
reloadPage: true,
entries: {
contentScript: 'content',
background: 'background'
}
})
);
}
if (analyze) {
config.plugins.push(new BundleAnalyzerPlugin());
}
return config;
};