-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.cjs
92 lines (87 loc) · 1.93 KB
/
webpack.config.cjs
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 CopyPlugin = require('copy-webpack-plugin')
const path = require('path')
const pkgDir = require('pkg-dir')
const pkgUp = require('pkg-up')
const WebPackVersionFilePlugin = require('webpack-version-file-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const { ProgressPlugin } = require('webpack')
const PROD_SOURCEMAPS = true
const prod = process.env.NODE_ENV === 'production'
const dev = !prod
const mode = prod ? 'production' : 'development'
const devtool = PROD_SOURCEMAPS || dev ? 'inline-source-map' : 'none'
module.exports = {
mode,
devtool,
entry: Object.fromEntries(
['background', 'contentScript', 'page'].map(entry => [
entry,
`./src/entrypoints/${entry}`,
])
),
output: {
publicPath: 'chrome-extension://ebihioehgamedmkomodfopiiflljphif/',
path: path.resolve(pkgDir.sync(), 'build', 'unpacked'),
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
plugins: [
new ProgressPlugin(),
// new CleanWebpackPlugin({
// // TODO: figure out why manifest.json gets removed
// cleanAfterEveryBuildPatterns: ['**/*', '!manifest.json'],
// verbose: true,
// }),
new CopyPlugin({
patterns: [
{
from: 'src/static/*.png',
flatten: true,
},
],
}),
new WebPackVersionFilePlugin({
packageFile: path.join(pkgUp.sync()),
outputFile: path.join(
pkgDir.sync(),
'build',
'unpacked',
'manifest.json'
),
template: path.join(
pkgDir.sync(),
'src',
'static',
'manifest.json'
),
}),
],
module: {
rules: [
{
test: /\.(mj|j|t)sx?$/i,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|svg|jpg|gif)$/,
loader: 'file-loader',
options: {
outputPath: 'images',
},
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
loader: 'file-loader',
options: {
outputPath: 'fonts',
},
},
],
},
}