Skip to content

Commit

Permalink
feat: bundle dts file (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 authored Nov 21, 2024
1 parent 3b9d94f commit b21f40e
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 60 deletions.
1 change: 1 addition & 0 deletions packages/theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"devDependencies": {
"@vanilla-extract/css": "^1.11.1",
"@vanilla-extract/vite-plugin": "^3.8.2",
"dts-bundle-generator": "^9.5.1",
"vite": "^4.3.9",
"vite-plugin-dts": "^2.3.0"
}
Expand Down
30 changes: 28 additions & 2 deletions packages/theme/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from 'node:fs';
import { resolve } from 'node:path';

import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
import { generateDtsBundle } from 'dts-bundle-generator';
import { fileURLToPath } from 'url';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
Expand All @@ -18,10 +20,34 @@ export default defineConfig({
index: resolve(__dirname, 'src/index.ts'),
css: resolve(__dirname, 'src/index.css.ts'),
'v2/index': resolve(__dirname, 'src/v2/index.ts'),
'presets/typography': resolve(__dirname, 'src/presets/typography.css.ts'),
'presets/typography': resolve(
__dirname,
'src/presets/typography.css.ts'
),
},
name: 'ToEverythingTheme',
},
},
plugins: [dts(), vanillaExtractPlugin()],
plugins: [
dts({
afterBuild() {
const inputs = [
resolve(__dirname, 'dist/index.d.ts'),
resolve(__dirname, 'dist/v2/index.d.ts'),
];

const dtsFiles = generateDtsBundle(
inputs.map(filePath => ({ filePath })),
{
preferredConfigPath: resolve(__dirname, 'tsconfig.json'),
}
);
// write back to source
dtsFiles.forEach((file, index) => {
fs.writeFileSync(inputs[index], file, 'utf-8');
});
},
}),
vanillaExtractPlugin(),
],
});
146 changes: 88 additions & 58 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b21f40e

Please sign in to comment.