-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrspack.config.mjs
85 lines (79 loc) · 1.71 KB
/
rspack.config.mjs
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
import path from 'node:path'
import url from 'node:url'
const isProd = process.env.NODE_ENV === 'production'
const isDev = process.env.NODE_ENV === 'development'
if (!isProd && !isDev) {
throw new Error(`Unknown env ${process.env.NODE_ENV}`)
}
const root = path.dirname(path.resolve(url.fileURLToPath(import.meta.url)))
const paths = {
root,
output: path.join(root, './dist'),
}
/**
* @type {import('@rspack/cli').Configuration}
*/
const config = {
mode: isProd ? 'production' : 'development',
entry: './src/main',
output: {
clean: true,
path: paths.output,
filename: './assets/[name]-[hash:8][ext]',
// Rspack has the same HMR issue as https://github.com/webpack-contrib/mini-css-extract-plugin/issues/444
cssFilename: `./styles/[name]${isProd ? '-[hash:8]' : ''}[ext]`,
},
experiments: {
newSplitChunks: true,
},
optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
reacts: {
test: /[\\/](react|react-dom)[\\/]/,
priority: 0,
},
},
},
},
builtins: {
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
},
html: [
{
template: './index.html',
},
],
copy: {
patterns: [
{
from: 'public',
},
],
},
},
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
},
},
},
],
type: 'css',
},
],
},
}
export default config