-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathwebpack.config.js
103 lines (95 loc) · 2.53 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
93
94
95
96
97
98
99
100
101
102
const CopyPlugin = require('copy-webpack-plugin');
const GenerateJsonFromJsPlugin = require('generate-json-from-js-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const dotenv = require('dotenv');
const { join } = require('path');
const { inDev } = require("./helpers");
dotenv.config();
const browsers = [
'chrome'
];
const Root = join(__dirname, '..');
const Source = join(Root, 'src');
const Dist = join(Root, 'dist');
const Public = join(Root, 'public');
const Background = join(Source, 'background');
const Content = join(Source, 'content');
const SidePanel = join(Source, 'sidePanel');
const Lib = join(Source, 'lib');
const Options = join(Source, 'options');
const config = {
mode: process.env.NODE_ENV,
target: 'web',
devtool: inDev() ? 'source-map' : undefined,
entry: {
background: join(Background, 'index.ts'),
content: join(Content, 'index.tsx'),
app: join(SidePanel, 'index.tsx')
},
module: { rules: require('./rules') },
resolve: {
extensions: ['.js', '.ts', '.jsx', '.tsx', '.css', '.scss'],
alias: {
lib: Lib,
background: Background,
sidePanel: SidePanel,
content: Content,
assets: Public,
options: Options,
...require('./aliases')
}
},
plugins: [
...require('./plugins'),
new HtmlWebpackPlugin(
{
inject: 'body',
template: join(SidePanel, 'index.html'),
filename: 'assets/sidePanel.html',
chunks: ['app']
}),
...browsers.map(browser => new GenerateJsonFromJsPlugin({
path: join(__dirname, 'manifest', `${browser}.js`),
filename: 'manifest.json',
options: {
replacer: (key, value) => {
switch (key) {
case 'extension_pages':
return value.replace(/\s+/g, ' ');
default:
return value;
}
}
}
})),
new CopyPlugin({
patterns: [
{
from: Public,
to: 'assets'
}
]
})
],
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/].*[\\/]/,
name: 'assets/vendor',
chunks: chunk => chunk.name !== "background"
}
}
}
}
};
const buildConfig = browser => ({
...config,
name: browser,
output: {
path: join(Dist, browser),
filename: '[name].js',
publicPath: process.env.EXTENSION_PUBLIC_PATH
}
});
module.exports = buildConfig(process.env.BROWSER || 'chrome');