You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/en/guide/basic/typescript.mdx
+27Lines changed: 27 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,3 +59,30 @@ export default {
59
59
},
60
60
};
61
61
```
62
+
63
+
## Path Extensions
64
+
65
+
When importing another module in a TypeScript module, TypeScript allows using the `.js` file extension:
66
+
67
+
```ts title="src/index.ts"
68
+
// The actual referenced module could be `./some-module.ts` or `./some-module.tsx`
69
+
import { someFn } from'./some-module.js';
70
+
```
71
+
72
+
Rsbuild supports this feature through Rspack's [extensionAlias](https://rspack.dev/config/resolve#resolveextensionalias) configuration. In TypeScript projects, Rsbuild adds the following configuration by default:
73
+
74
+
```js
75
+
constrspackConfig= {
76
+
resolve: {
77
+
extensionAlias: {
78
+
'.js': ['.ts', '.tsx', '.js'],
79
+
'.jsx': ['.tsx', '.jsx'],
80
+
},
81
+
},
82
+
};
83
+
```
84
+
85
+
This means:
86
+
87
+
- You can use the `.js` extension to import `.ts` or `.tsx` files.
88
+
- You can use the `.jsx` extension to import `.tsx` files.
0 commit comments