Skip to content

Commit c727646

Browse files
authored
chore(build): enable Rslib's dts.build (#3948)
1 parent cacffeb commit c727646

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

packages/core/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@
4646
"types.d.ts"
4747
],
4848
"scripts": {
49-
"build": "pnpm run build:types && rslib build",
50-
"build:types": "rimraf ./dist-types && tsc --build --force --emitDeclarationOnly",
51-
"dev": "pnpm run build:types && rslib build --watch",
49+
"build": "rslib build",
50+
"dev": "rslib build --watch",
5251
"prebundle": "prebundle"
5352
},
5453
"dependencies": {

packages/core/rslib.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
3+
import { pluginCleanTscCache } from '@rsbuild/config/rslib.config';
34
import { defineConfig } from '@rslib/core';
45
import type { Configuration } from '@rspack/core';
56
import pkgJson from './package.json';
@@ -81,7 +82,10 @@ export default defineConfig({
8182
__dirname: true,
8283
},
8384
},
84-
plugins: [pluginFixDtsTypes],
85+
plugins: [pluginFixDtsTypes, pluginCleanTscCache],
86+
dts: {
87+
build: true,
88+
},
8589
},
8690
// Node / CJS
8791
{
@@ -124,6 +128,7 @@ export default defineConfig({
124128
overlay: 'src/client/overlay.ts',
125129
},
126130
define: {
131+
// use define to avoid compile time evaluation of __webpack_hash__
127132
WEBPACK_HASH: '__webpack_hash__',
128133
},
129134
},

pnpm-lock.yaml

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

scripts/config/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"version": "1.0.1",
44
"private": true,
55
"devDependencies": {
6+
"@rsbuild/core": "workspace:*",
7+
"@rslib/core": "0.0.16",
68
"@types/node": "^22.9.0",
79
"typescript": "^5.6.3"
810
}

scripts/config/rslib.config.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import type { RsbuildPlugin } from '@rsbuild/core';
14
import { type LibConfig, defineConfig } from '@rslib/core';
25

36
export const commonExternals: Array<string | RegExp> = [
47
'webpack',
58
/[\\/]compiled[\\/]/,
69
];
710

11+
// Clean tsc cache to ensure the dts files can be generated correctly
12+
export const pluginCleanTscCache: RsbuildPlugin = {
13+
name: 'plugin-clean-tsc-cache',
14+
setup(api) {
15+
api.onBeforeBuild(() => {
16+
const tsbuildinfo = path.join(
17+
api.context.rootPath,
18+
'tsconfig.tsbuildinfo',
19+
);
20+
if (fs.existsSync(tsbuildinfo)) {
21+
fs.rmSync(tsbuildinfo);
22+
}
23+
});
24+
},
25+
};
26+
827
export const esmConfig: LibConfig = {
928
format: 'esm',
1029
syntax: 'es2021',
11-
dts: { bundle: false },
30+
dts: {
31+
build: true,
32+
},
33+
plugins: [pluginCleanTscCache],
1234
};
1335

1436
export const cjsConfig: LibConfig = {

0 commit comments

Comments
 (0)