-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.ts
89 lines (83 loc) · 2.11 KB
/
webpack.config.ts
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
/* eslint-disable node/no-unpublished-require */
/* eslint-disable @typescript-eslint/ban-ts-comment */
/* eslint-disable node/no-unpublished-import */
import path from 'path'
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin'
import { CleanWebpackPlugin } from 'clean-webpack-plugin'
import DotenvFlow from 'dotenv-flow-webpack'
import webpack from 'webpack'
const isDev = process.env.NODE_ENV !== 'production'
const srcDir = path.join(__dirname, 'src')
const outDir = path.join(__dirname, 'dist/js')
function getEntry(name: string) {
return [path.join(srcDir, name), ...(isDev ? [`mv3-hot-reload/${name}`] : [])]
}
const config: webpack.Configuration = {
watch: isDev,
mode: isDev ? 'development' : 'production',
devtool: isDev ? 'inline-source-map' : 'source-map',
// @ts-ignore
devServer: {
hot: true,
firewall: false,
port: 3912,
devMiddleware: {
writeToDisk: true,
},
static: {
watch: false,
},
client: {
host: 'localhost',
},
},
entry: {
popup: path.join(srcDir, 'popup'),
options: path.join(srcDir, 'options'),
background: getEntry('background'),
content: getEntry('content'),
},
output: {
path: outDir,
filename: '[name].js',
},
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader', 'postcss-loader'],
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: require.resolve('babel-loader'),
options: {
// auto insert react runtime
presets: [['react-app', { runtime: 'automatic' }]],
plugins: [isDev && require.resolve('react-refresh/babel')].filter(
Boolean,
),
},
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
alias: {
'@': srcDir,
},
},
// @ts-ignore
plugins: [
new CleanWebpackPlugin(),
new DotenvFlow(),
new webpack.EnvironmentPlugin({
MV3_HOT_RELOAD_PORT: 7761,
}),
isDev &&
new ReactRefreshWebpackPlugin({
overlay: false,
}),
].filter(Boolean),
}
export default config