-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathrspack.config.ts
More file actions
114 lines (108 loc) · 2.51 KB
/
rspack.config.ts
File metadata and controls
114 lines (108 loc) · 2.51 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
import {
type RspackOptions,
DefinePlugin,
ProgressPlugin,
HtmlRspackPlugin,
} from '@rspack/core'
import ReactRefreshPlugin from '@rspack/plugin-react-refresh'
import { launchEditorMiddleware } from '@react-dev-inspector/middleware'
const isDev = process.env.NODE_ENV === 'development'
const publicPath = isDev ? '/' : '/rspack/'
const config: RspackOptions = ({
context: process.cwd(),
devServer: {
setupMiddlewares(middlewares) {
/**
* react-dev-inspector server config for rspack
*/
middlewares.unshift(launchEditorMiddleware)
return middlewares
},
},
entry: {
main: './src/main.tsx',
},
output: {
publicPath,
filename: '[name].[hash].js',
chunkFilename: '[id].[hash].chunk.js',
assetModuleFilename: '[name].[hash].[ext]',
uniqueName: Math.random().toString(36).slice(2),
},
devtool: false,
optimization: {
minimize: false,
},
resolve: {
extensions: [
'...',
'.ts',
'.tsx',
'.css',
'.less',
],
},
module: {
rules: [
{
test: /\.svg$/,
type: 'asset',
},
{
test: /\.css$/,
type: 'css',
use: [
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: {
'tailwindcss/nesting': {},
tailwindcss: {},
autoprefixer: {},
},
},
},
},
],
},
{
test: /\.tsx?$/,
exclude: [/[\\/]node_modules[\\/]/],
loader: 'builtin:swc-loader',
options: {
sourceMap: isDev,
jsc: {
parser: {
syntax: 'typescript',
decorators: true,
jsx: true,
},
externalHelpers: true,
transform: {
decoratorMetadata: true,
// useDefineForClassFields: true,
react: {
runtime: 'automatic',
development: isDev,
// https://www.rspack.dev/blog/announcing-0-4#deprecating-builtinreactrefresh
refresh: isDev,
},
},
},
},
},
],
},
plugins: [
new DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
}),
new ProgressPlugin({}),
new HtmlRspackPlugin({
template: './index.html',
}),
isDev && new ReactRefreshPlugin(),
],
})
export default config