-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathrsbuild.config.ts
56 lines (52 loc) · 1.53 KB
/
rsbuild.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
import { environments } from "@dzcode.io/utils/dist/config/environment";
import { defineConfig } from "@rsbuild/core";
import { pluginReact } from "@rsbuild/plugin-react";
import { readFileSync } from "fs";
let stage = process.env.STAGE;
if (!environments.includes(stage)) {
console.log(`⚠️ No STAGE provided, falling back to "development"`);
stage = "development";
}
let bundleInfo: { version: string } = {
version: `v${require("./package.json").version as string}`, // eslint-disable-line @typescript-eslint/no-require-imports
};
try {
bundleInfo = JSON.parse(readFileSync(".bundle-info.json").toString()) as typeof bundleInfo;
} catch (error) {
console.log(`no .bundle-info.json found`, error);
}
export default defineConfig({
plugins: [pluginReact()],
source: {
alias: {
src: "./src",
},
define: {
"window.bundleInfo": JSON.stringify(bundleInfo),
},
},
html: {
template: "./src/_entry/index.html",
favicon: "./src/assets/ico/favicon.ico",
templateParameters: {
stage,
},
},
server: {
port: 8080,
},
output: {
distPath: {
root: "./bundle",
css: `w/${bundleInfo.version}/css`,
cssAsync: `w/${bundleInfo.version}/css/async`,
js: `w/${bundleInfo.version}/js`,
jsAsync: `w/${bundleInfo.version}/js/async`,
image: `w/${bundleInfo.version}/images`,
font: `w/${bundleInfo.version}/fonts`,
media: `w/${bundleInfo.version}/media`,
svg: `w/${bundleInfo.version}/svg`,
wasm: `w/${bundleInfo.version}/wasm`,
},
},
});