diff --git a/package.json b/package.json index 6c3640b..03cd7c6 100644 --- a/package.json +++ b/package.json @@ -90,6 +90,7 @@ "postcss-nested": "6.0.1", "prettier": "3.2.5", "react": "18.2.0", + "rollup-plugin-preserve-directives": "0.4.0", "tailwindcss": "3.4.1", "tslib": "2.6.2", "typescript": "5.4.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ed0df75..a9b1eda 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -57,6 +57,9 @@ importers: react: specifier: 18.2.0 version: 18.2.0 + rollup-plugin-preserve-directives: + specifier: 0.4.0 + version: 0.4.0(rollup@4.13.0) tailwindcss: specifier: 3.4.1 version: 3.4.1 @@ -71,7 +74,7 @@ importers: version: 5.1.6(@types/node@20.11.28) vite-plugin-dts: specifier: 3.7.3 - version: 3.7.3(@types/node@20.11.28)(typescript@5.4.2)(vite@5.1.6) + version: 3.7.3(@types/node@20.11.28)(rollup@4.13.0)(typescript@5.4.2)(vite@5.1.6) vite-tsconfig-paths: specifier: 4.3.2 version: 4.3.2(typescript@5.4.2)(vite@5.1.6) @@ -1570,7 +1573,7 @@ packages: react: 18.2.0 dev: false - /@rollup/pluginutils@5.1.0: + /@rollup/pluginutils@5.1.0(rollup@4.13.0): resolution: {integrity: sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==} engines: {node: '>=14.0.0'} peerDependencies: @@ -1582,6 +1585,7 @@ packages: '@types/estree': 1.0.5 estree-walker: 2.0.2 picomatch: 2.3.1 + rollup: 4.13.0 dev: true /@rollup/rollup-android-arm-eabi@4.13.0: @@ -6823,6 +6827,16 @@ packages: glob: 7.2.3 dev: true + /rollup-plugin-preserve-directives@0.4.0(rollup@4.13.0): + resolution: {integrity: sha512-gx4nBxYm5BysmEQS+e2tAMrtFxrGvk+Pe5ppafRibQi0zlW7VYAbEGk6IKDw9sJGPdFWgVTE0o4BU4cdG0Fylg==} + peerDependencies: + rollup: 2.x || 3.x || 4.x + dependencies: + '@rollup/pluginutils': 5.1.0(rollup@4.13.0) + magic-string: 0.30.8 + rollup: 4.13.0 + dev: true + /rollup@4.13.0: resolution: {integrity: sha512-3YegKemjoQnYKmsBlOHfMLVPPA5xLkQ8MHLLSw/fBrFaVkEayL51DilPpNNLq1exr98F2B1TzrV0FUlN3gWRPg==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} @@ -7823,7 +7837,7 @@ packages: - terser dev: true - /vite-plugin-dts@3.7.3(@types/node@20.11.28)(typescript@5.4.2)(vite@5.1.6): + /vite-plugin-dts@3.7.3(@types/node@20.11.28)(rollup@4.13.0)(typescript@5.4.2)(vite@5.1.6): resolution: {integrity: sha512-26eTlBYdpjRLWCsTJebM8vkCieE+p9gP3raf+ecDnzzK5E3FG6VE1wcy55OkRpfWWVlVvKkYFe6uvRHYWx7Nog==} engines: {node: ^14.18.0 || >=16.0.0} peerDependencies: @@ -7834,7 +7848,7 @@ packages: optional: true dependencies: '@microsoft/api-extractor': 7.39.0(@types/node@20.11.28) - '@rollup/pluginutils': 5.1.0 + '@rollup/pluginutils': 5.1.0(rollup@4.13.0) '@vue/language-core': 1.8.27(typescript@5.4.2) debug: 4.3.4 kolorist: 1.8.0 diff --git a/vite.config.ts b/vite.config.ts index 8d0c200..d0e8e98 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,6 +1,7 @@ -import { readFileSync } from 'fs' +import { readFileSync, writeFileSync } from 'fs' import { resolve } from 'path' import react from '@vitejs/plugin-react' +import { preserveDirectives } from 'rollup-plugin-preserve-directives' import { defineConfig } from 'vite' import dts from 'vite-plugin-dts' @@ -16,7 +17,11 @@ export default defineConfig({ plugins: [ react(), dts({ - rollupTypes: true, + // rollupTypes: true, + beforeWriteFile: (filePath, content) => { + writeFileSync(filePath.replace('.d.ts', '.d.cts'), content) + return { filePath, content } + }, }), ], resolve: { @@ -41,6 +46,7 @@ export default defineConfig({ 'react/jsx-runtime', ...Object.keys(globals), ], + plugins: [preserveDirectives({})], }, }, })