-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrspack.config.ts
More file actions
59 lines (53 loc) · 1.51 KB
/
rspack.config.ts
File metadata and controls
59 lines (53 loc) · 1.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
import fs from 'node:fs/promises';
import path from 'node:path';
import * as utils from '@krutoo/utils/rspack';
import { type Configuration } from '@rspack/core';
import packageJson from './package.json' with { type: 'json' };
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};`);
}
const config: Configuration = {
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]),
),
plugins: [
utils.pluginTypeScript(),
utils.pluginCSS({
extract: {
filename: '../css/showcase.css',
},
cssModules: {
auto: /\.(module|m)\.css$/i,
localIdentName: 'showcase__[local]--[hash:4]',
exportLocalsConvention: 'as-is',
namedExport: false,
getJSON: emitCssModuleExports,
},
}),
],
experiments: {
css: false,
outputModule: true,
},
};
export default config;