-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
64 lines (62 loc) · 1.48 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
const { DefinePlugin } = require('webpack');
const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CustomizeRule, mergeWithRules } = require('webpack-merge');
const { resolve } = require('path');
const development = require('./webpack.dev');
const production = require('./webpack.prod');
const common = (mode) => ({
mode,
devtool: false,
output: {
path: resolve(process.cwd(), 'dist'),
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
plugins: [new TsconfigPathsPlugin({})],
},
module: {
rules: [
{
test: /\.css$/,
exclude: /node_modules/,
use: [
{
loader: 'css-loader',
options: {
modules: { auto: true },
},
},
'postcss-loader',
],
},
{
test: /\.(png|jpe?g|gif|svg)$/,
type: 'asset/resource',
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: 'src/index.html',
}),
new DefinePlugin({
__MODE__: JSON.stringify(mode),
}),
],
});
module.exports = (_, { mode = 'none' }) =>
mergeWithRules({
mode,
module: {
rules: {
test: CustomizeRule.Match,
use: CustomizeRule.Prepend,
},
},
})(common(mode), mode === 'production' ? production : development);