From 1c9d23981d032cab8fbe4faf443b2c1ef9b36d06 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Tue, 17 Dec 2024 11:42:18 +0800 Subject: [PATCH] fix: type missing when set moduleResolution node16+ --- packages/core/rslib.config.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/core/rslib.config.ts b/packages/core/rslib.config.ts index ac2a90e47..eaf5339c5 100644 --- a/packages/core/rslib.config.ts +++ b/packages/core/rslib.config.ts @@ -1,5 +1,29 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import type { RsbuildPlugin } from '@rsbuild/core'; import { defineConfig } from 'rslib'; +const pluginFixDtsTypes: RsbuildPlugin = { + name: 'fix-dts-types', + setup(api) { + api.onAfterBuild(() => { + const typesDir = path.join(process.cwd(), 'dist-types'); + const pkgPath = path.join(typesDir, 'package.json'); + if (!fs.existsSync(typesDir)) { + fs.mkdirSync(typesDir); + } + fs.writeFileSync( + pkgPath, + JSON.stringify({ + '//': 'This file is for making TypeScript work with moduleResolution node16+.', + version: '1.0.0', + }), + 'utf8', + ); + }); + }, +}; + export default defineConfig({ lib: [ { @@ -11,6 +35,7 @@ export default defineConfig({ }, }, ], + plugins: [pluginFixDtsTypes], source: { entry: { index: './src/index.ts',