-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrspack.config.ts
93 lines (88 loc) · 2.3 KB
/
rspack.config.ts
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
import fs from 'node:fs/promises';
import path from 'node:path';
import rspack, { type Configuration } from '@rspack/core';
import packageJson from './package.json';
export default {
entry: {
bundle: './src/runtime-showcase/index.ts',
},
output: {
path: path.resolve(import.meta.dirname, 'temp'),
filename: '[name].js',
clean: true,
},
mode: 'development',
devtool: false,
externals: Object.fromEntries(
Object.entries(packageJson.dependencies).map(([key]) => [key, key]),
),
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
tsConfig: {
configFile: path.resolve(import.meta.dirname, './tsconfig.json'),
},
},
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
loader: 'builtin:swc-loader',
options: {
sourceMap: true,
jsc: {
parser: {
syntax: 'typescript',
jsx: true,
},
transform: {
react: {
runtime: 'automatic',
},
},
},
},
},
{
test: /\.css$/i,
use: [
rspack.CssExtractRspackPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
auto: /\.(module|m)\.css$/i,
localIdentName: 'showcase__[local]--[hash:4]',
exportLocalsConvention: 'as-is',
namedExport: false,
getJSON: emitCssModuleExports,
},
},
},
],
},
],
},
plugins: [
new rspack.CssExtractRspackPlugin({
filename: path.resolve(process.cwd(), 'css/showcase-styles.css'),
}),
],
experiments: {
css: false,
outputModule: true,
},
} satisfies Configuration;
async function emitCssModuleExports(data: {
exports: Array<{ name: string; value: string }>;
resourcePath: string;
}) {
const targetFilename = path.join('dist', path.relative('./src', `${data.resourcePath}.js`));
await fs.mkdir(path.dirname(targetFilename), { recursive: true });
const content = JSON.stringify(
Object.fromEntries(data.exports.map(item => [item.name, item.value])),
null,
2,
);
await fs.writeFile(targetFilename, `export default ${content};`);
}