-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rspack.ts
More file actions
110 lines (89 loc) · 2.1 KB
/
Copy pathbuild.rspack.ts
File metadata and controls
110 lines (89 loc) · 2.1 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
import './_esm_'
import glob from 'fast-glob'
import { resolve } from 'path'
import { rspack } from '@rspack/core'
import { clean, modules, split_modules } from './build.utils'
import config from './config.rspack'
import type { Configuration } from '@rspack/core'
const { sync } = glob
const configs = [] as Array<Configuration>
clean()
const getEntry = (name: string, split?: boolean) => {
if (!split) {
return { entry: { main: `./packages/${name}/src/index.ts` } } as Configuration
}
const entry = sync([
resolve(__dirname, `./packages/${name}/src/*.ts`),
resolve(__dirname, `./packages/${name}/src/*.tsx`)
]).reduce((total, item) => {
const name = item.split('/').at(-1)!.split('.').at(0)!
total[name] = item
return total
}, {})
return { entry } as Configuration
}
const getOutput = (name: string, type: 'dev' | 'prod', split?: boolean) => {
return {
output: {
filename: `${split ? '[name]' : 'index'}.${type}.mjs`,
path: resolve(__dirname, `./packages/${name}/dist`),
clean: false,
module: true,
library: { type: 'module' }
}
} as Configuration
}
const getOptimization = (dev: boolean) => {
if (dev) {
return {
optimization: { minimize: false }
} as Configuration
}
return {}
}
const getPlugins = (dev: boolean) => {
return { plugins: [new rspack.DefinePlugin({ __DEV__: dev ? true : false })] } as Configuration
}
modules.forEach(name => {
configs.push(
{
...config,
...getEntry(name),
...getOutput(name, 'dev'),
...getOptimization(true),
...getPlugins(true)
},
{
...config,
...getEntry(name),
...getOutput(name, 'prod'),
...getOptimization(false),
...getPlugins(false)
}
)
})
split_modules.forEach(name => {
configs.push(
{
...config,
...getEntry(name, true),
...getOutput(name, 'dev', true),
...getOptimization(true),
...getPlugins(true)
},
{
...config,
...getEntry(name, true),
...getOutput(name, 'prod', true),
...getOptimization(false),
...getPlugins(false)
}
)
})
rspack(configs, async (e, stats) => {
const err = e || stats?.hasErrors?.()
if (err) {
console.log(err)
return
}
})