Skip to content

Commit b8319d1

Browse files
authored
feat: add example for collectTypeScriptInfo (#307)
1 parent 60ec319 commit b8319d1

File tree

7 files changed

+343
-200
lines changed

7 files changed

+343
-200
lines changed

pnpm-lock.yaml

Lines changed: 254 additions & 200 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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-canary/cli": "1.4.0-canary-30c614aa-20250626094549",
12+
"@rspack-canary/core": "1.4.0-canary-30c614aa-20250626094549"
13+
}
14+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// @ts-check
2+
3+
/** @type {import("@rspack-canary/core").Configuration} */
4+
export default {
5+
entry: {
6+
main: "./src/index.ts",
7+
},
8+
experiments: {
9+
css: true,
10+
inlineEnum: true,
11+
typeReexportsPresence: true,
12+
},
13+
mode: "production",
14+
optimization: {
15+
// disable minimize so you can understand the output
16+
minimize: false,
17+
},
18+
resolve: {
19+
extensions: [".ts", "..."],
20+
},
21+
module: {
22+
parser: {
23+
javascript: {
24+
typeReexportsPresence: "tolerant"
25+
}
26+
},
27+
rules: [
28+
{
29+
test: /\.ts$/,
30+
use: {
31+
loader: "builtin:swc-loader",
32+
/** @type {import("@rspack-canary/core").SwcLoaderOptions} */
33+
options: {
34+
jsc: {
35+
parser: {
36+
syntax: "typescript",
37+
},
38+
},
39+
rspackExperiments: {
40+
collectTypeScriptInfo: {
41+
typeExports: true,
42+
exportedEnum: true,
43+
}
44+
}
45+
},
46+
},
47+
type: "javascript/auto",
48+
},
49+
],
50+
},
51+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum Kind {
2+
A,
3+
B,
4+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Kind, TypeA, TypeB } from './reexports';
2+
3+
const a: TypeA = 42;
4+
const b: TypeB = 'rspack';
5+
6+
console.log(a, b);
7+
8+
// Take a look at the build output (dist/main.js)
9+
// Should inline Kind.A to 0 and Kind.B to 1 here since we configured inlineEnum
10+
console.log(Kind.A, Kind.B);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export * from './enums';
2+
3+
// Should not report ESModulesLinkingWarning since we configured `typeReexportsPresence: "tolerant"`
4+
// case 1:
5+
export { TypeA } from './types';
6+
// case 2:
7+
import { TypeB } from './types';
8+
export { TypeB };
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export type TypeA = number;
2+
export type TypeB = string;

0 commit comments

Comments
 (0)