-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwebpack.common.js
More file actions
76 lines (74 loc) · 1.74 KB
/
Copy pathwebpack.common.js
File metadata and controls
76 lines (74 loc) · 1.74 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
const path = require('path');
const parser = require('yargs-parser');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ChromeExtensionReloader = require('webpack-chrome-extension-reloader');
function getChromeReloaderPlugin() {
const plugins = [];
// only add plugin if the --watch flag is set
if (parser(process.argv).watch) {
plugins.push(
new ChromeExtensionReloader({
// The entries used for the content/background scripts; use entry names, not the file name or path
entries: {
background: 'background',
contentScript: 'content',
},
}),
);
}
return plugins;
}
module.exports = {
entry: {
background: path.join(__dirname, 'src/ts/background.ts'),
content: path.join(__dirname, 'src/ts/content.ts'),
options: path.join(__dirname, 'src/ts/options.ts'),
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
},
module: {
rules: [
{
exclude: /node_modules/,
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
},
resolve: {
modules: [
__dirname,
'node_modules',
],
extensions: ['.ts', '.tsx', '.js'],
},
plugins: [
// clean build directory
new CleanWebpackPlugin(),
// copy assets
new CopyWebpackPlugin([
{
context: 'src/resources',
from: '**/*.*',
},
]),
...getChromeReloaderPlugin(),
],
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'initial',
},
},
},
},
};