-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathwebpack.config.js
74 lines (70 loc) · 1.73 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
const path = require('path')
const CopyPlugin = require('copy-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const { EnvironmentPlugin } = require('webpack')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development'
const config = {
devtool: 'inline-source-map',
mode,
entry: {
background: './background.js',
contentscript: './contentscript.js',
options_script: './lib/options_script.js',
tat_popup: './lib/tat_popup.js',
popup: './lib/popup.js'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
// Without this custom elements don't work on youtube... wtf
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
plugins: ['@babel/plugin-transform-classes']
}
}
},
{
test: /\.html$/,
type: 'asset/source'
}
]
},
plugins: [
new EnvironmentPlugin(
mode === 'production' ? [
'API_SECRET',
'MEASUREMENT_ID',
'MANIFEST_V3'
] : {
'API_SECRET': '123456',
'MEASUREMENT_ID': '343434',
'MANIFEST_V3': 'false'
}
),
new CleanWebpackPlugin(),
new CopyPlugin({
patterns: [
{
from: process.env.MANIFEST_V3 === 'true' ? 'manifest_v3.json' : 'manifest_v2.json',
to: 'manifest.json'
},
'*.png',
'options.html',
]
})
]
}
if (mode === 'production') {
config.optimization = {
minimizer: [new UglifyJsPlugin({test: /\.js(\?.*)?$/i})]
}
}
module.exports = config