generated from frndxfrnd/react-compiled-twin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
98 lines (92 loc) · 2.41 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const path = require('path')
const webpack = require('webpack')
const TerserPlugin = require('terser-webpack-plugin')
const ProgressBarPlugin = require('simple-progress-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin').CleanWebpackPlugin
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
module.exports = [
async (_env, argv) => {
if (argv.mode) {
process.env.NODE_ENV = argv.mode
}
if (argv.hot) {
process.env.HOT = argv.hot
}
const dev = process.env.NODE_ENV === 'development'
const hot = process.env.HOT !== undefined
return {
context: __dirname,
entry: [
'./src/index'
],
output: {
filename: '[name].[contenthash].js',
chunkFilename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
target: 'web',
devtool: dev ? 'eval-source-map' : undefined,
devServer: {
contentBase: path.resolve(__dirname, 'dist'),
historyApiFallback: {
index: 'index.html'
}
},
plugins: [
new CleanWebpackPlugin(),
new ProgressBarPlugin({
format: 'minimal'
}),
new HtmlWebpackPlugin({
template: 'src/template.ejs',
minify: {
ignoreCustomComments: [
/^made with ❤️$/
]
}
}),
dev && hot && new webpack.HotModuleReplacementPlugin(),
dev && hot && new ReactRefreshWebpackPlugin()
].filter(x => x),
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: /(node_modules)/,
use: [
'babel-loader'
]
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
}
]
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
alias: {
'@': [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'src/components')
]
}
},
optimization: {
minimizer: [
new TerserPlugin()
],
moduleIds: 'deterministic',
splitChunks: {
chunks: 'all',
maxSize: 244000
}
}
}
}
]