Skip to content

Commit f9fe36a

Browse files
authored
Update enhance typescript examples (#334)
1 parent d35dd85 commit f9fe36a

File tree

16 files changed

+310
-121
lines changed

16 files changed

+310
-121
lines changed

pnpm-lock.yaml

Lines changed: 160 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rspack/collect-typescript-info/src/index.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

rspack/collect-typescript-info/package.json renamed to rspack/inline-const-enum/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build": "rspack build"
99
},
1010
"devDependencies": {
11-
"@rspack/cli": "1.4.11",
12-
"@rspack/core": "1.4.11"
11+
"@rspack/cli": "1.5.0-rc.0",
12+
"@rspack/core": "1.5.0-rc.0"
1313
}
1414
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// @ts-check
2+
3+
/** @type {import("@rspack/core").Configuration} */
4+
export default {
5+
entry: {
6+
main: "./src/index.ts",
7+
},
8+
experiments: {
9+
inlineEnum: true,
10+
},
11+
mode: "production",
12+
optimization: {
13+
// disable minimize so you can understand the output
14+
minimize: false,
15+
},
16+
resolve: {
17+
extensions: [".ts", "..."],
18+
},
19+
module: {
20+
rules: [
21+
{
22+
test: /\.ts$/,
23+
use: {
24+
loader: "builtin:swc-loader",
25+
/** @type {import("@rspack/core").SwcLoaderOptions} */
26+
options: {
27+
jsc: {
28+
parser: {
29+
syntax: "typescript",
30+
},
31+
transform: {
32+
tsEnumIsMutable: true,
33+
}
34+
},
35+
rspackExperiments: {
36+
collectTypeScriptInfo: {
37+
exportedEnum: 'const-only',
38+
}
39+
}
40+
},
41+
},
42+
type: "javascript/auto",
43+
},
44+
],
45+
},
46+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export enum Kind {
2+
A,
3+
B,
4+
}
5+
6+
export const enum ConstKind {
7+
A,
8+
B,
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Kind, ConstKind } from './enums';
2+
3+
// Take a look at the build output (dist/main.js)
4+
// Should not inline Kind.A and Kind.B here since inlineEnum is configured to 'const-only'.
5+
console.log(Kind.A, Kind.B);
6+
// Should inline ConstKind.A to 0 and ConstKind.B to 1 here since inlineEnum is configured to 'const-only'.
7+
console.log(ConstKind.A, ConstKind.B);

rspack/inline-const/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build": "rspack build"
99
},
1010
"devDependencies": {
11-
"@rspack/cli": "1.5.0-beta.0",
12-
"@rspack/core": "1.5.0-beta.0"
11+
"@rspack/cli": "1.5.0-rc.0",
12+
"@rspack/core": "1.5.0-rc.0"
1313
}
1414
}

rspack/inline-enum/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "example-builtin-swc-loader",
3+
"version": "1.0.0",
4+
"private": true,
5+
"license": "MIT",
6+
"main": "index.js",
7+
"scripts": {
8+
"build": "rspack build"
9+
},
10+
"devDependencies": {
11+
"@rspack/cli": "1.5.0-rc.0",
12+
"@rspack/core": "1.5.0-rc.0"
13+
}
14+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// @ts-check
2+
3+
/** @type {import("@rspack/core").Configuration} */
4+
export default {
5+
entry: {
6+
main: "./src/index.ts",
7+
},
8+
experiments: {
9+
inlineEnum: true,
10+
},
11+
mode: "production",
12+
optimization: {
13+
// disable minimize so you can understand the output
14+
minimize: false,
15+
},
16+
resolve: {
17+
extensions: [".ts", "..."],
18+
},
19+
module: {
20+
rules: [
21+
{
22+
test: /\.ts$/,
23+
use: {
24+
loader: "builtin:swc-loader",
25+
/** @type {import("@rspack/core").SwcLoaderOptions} */
26+
options: {
27+
jsc: {
28+
parser: {
29+
syntax: "typescript",
30+
}
31+
},
32+
rspackExperiments: {
33+
collectTypeScriptInfo: {
34+
exportedEnum: true,
35+
}
36+
}
37+
},
38+
},
39+
type: "javascript/auto",
40+
},
41+
],
42+
},
43+
};
File renamed without changes.

0 commit comments

Comments
 (0)