-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.cjs
102 lines (98 loc) · 2.56 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
93
94
95
96
97
98
99
100
101
102
const path = require('path');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const src = path.join(__dirname, 'src');
const mode = process.env.NODE_ENV ?? 'development';
const isProduction = mode === 'production';
const port = 8080;
const hotScript = 'webpack/hot/dev-server';
const clientScript = `webpack-dev-server/client?hot=true&protocol=ws&hostname=localhost&port=${port}`;
module.exports = {
mode,
entry: {
background: [path.join(src, 'app/chrome-extension/background/index.ts')],
programmers: [
path.join(src, 'app/chrome-extension/scripts/programmers/index.ts'),
],
boj: [path.join(src, 'app/chrome-extension/scripts/boj/index.ts')],
leetcode: [
path.join(src, 'app/chrome-extension/scripts/leetcode/index.ts'),
],
common_isolated: [
path.join(src, 'app/chrome-extension/scripts/common-isolated/index.ts'),
],
setting: [
path.join(src, 'app/user-config/index.ts'),
...(isProduction ? [] : [hotScript, clientScript]),
],
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
clean: true,
},
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /(node_modules)/,
use: {
loader: 'swc-loader',
options: {
jsc: {
parser: {
syntax: 'typescript',
},
transform: {
react: {
runtime: 'automatic',
},
},
},
},
},
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader', 'postcss-loader'],
},
],
},
resolve: {
extensions: ['.ts', '.js', '.jsx', '.tsx'],
alias: {
'~': path.resolve(__dirname, 'src'),
'@base': path.resolve(__dirname, 'src/base'),
},
},
devtool: isProduction ? false : 'inline-source-map',
plugins: [
new CopyPlugin({
patterns: [{ from: 'src/assets', to: '.' }],
options: {},
}),
new CleanWebpackPlugin(),
...(isProduction
? []
: [
new webpack.HotModuleReplacementPlugin(),
new ReactRefreshWebpackPlugin({
overlay: false,
}),
]),
],
devServer: {
port,
hot: false,
client: false,
allowedHosts: 'all',
devMiddleware: {
writeToDisk: true,
},
static: {
watch: false,
},
},
};