-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
66 lines (61 loc) · 1.82 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
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin'
import UnoCSS from '@unocss/webpack'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import path from 'path'
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
const mode = process.env.NODE_ENV ?? 'development'
const devMode = mode === 'development'
const overlay = false
const __dirname = import.meta.dirname
export default {
entry: [path.resolve(__dirname, 'src', 'index.tsx'), 'uno.css'],
mode,
devtool: devMode ? 'inline-source-map' : 'source-map',
output: {
path: path.resolve(__dirname, 'build'),
clean: true,
filename: 'bundle.[contenthash].js',
},
module: {
rules: [
{
test: /\.m?(js|ts)x?$/,
exclude: /node_modules/,
use: {
loader: 'swc-loader',
options: {
module: { type: 'nodenext' },
jsc: {
parser: { syntax: 'typescript', jsx: true, tsx: true },
transform: { react: { development: devMode, refresh: devMode } },
},
},
},
},
{ test: /\.css$/, use: [devMode ? 'style-loader' : MiniCssExtractPlugin.loader, 'css-loader'] },
{ test: /\.(png|jpg|gif)$/i, type: 'asset/resource' },
],
},
resolve: {
extensions: ['.js', '.tsx', '.ts'],
plugins: [
new TsconfigPathsPlugin({
baseUrl: 'src',
configFile: 'tsconfig.json',
extensions: ['.js', '.ts', '.tsx'],
}),
],
},
plugins: [
UnoCSS(),
new ReactRefreshWebpackPlugin({ overlay }),
new HtmlWebpackPlugin({ template: path.resolve(__dirname, 'public', 'index.html') }),
!devMode && new MiniCssExtractPlugin({ filename: 'bundle.[contenthash].css' }),
].filter(Boolean),
stats: 'errors-warnings',
infrastructureLogging: { debug: [name => name.includes('webpack-dev-server')] },
optimization: {
realContentHash: true,
}
}