构建一个组件库并意识到该包包含故事及其 .d 文件。 更改了 glob 以排除此问题,但 .d 文件尚未添加。我做错了什么?
使用 glob-tool 进行测试并且匹配。
Vite.config.ts:
import {defineConfig} from 'vite'
import react from '@vitejs/plugin-react'
import dts from 'vite-plugin-dts'
import {libInjectCss} from 'vite-plugin-lib-inject-css'
import {extname,relative,resolve} from 'path'
import {fileURLToPath} from 'node:url'
import {glob} from 'glob'
export default defineConfig({
plugins: [react(),libInjectCss(),dts({include: ['stories']})],
build: {
copyPublicDir: false,
lib: {
entry: resolve(__dirname,'stories/main.ts'),
formats: ['es'],
name: "components-lib",
},
rollupOptions: {
external: ['react','react/jsx-runtime'],
input: Object.fromEntries(
glob.sync('stories/**/!(*.stories.d|*.stories).{ts,tsx,js,jsx}').map(file => [
relative(
'stories',
file.slice(0,file.length-extname(file).length)
),
fileURLToPath(new URL(file,import.meta.url))
])
),
output: {
assetFileNames: 'assets/[name][extname]',
entryFileNames: '[name].js',
}
}
},
})
您将 dts 插件设置为包含故事。
相反,你应该排除它们:
示例:
plugins: [
dts({
exclude: ['**/*.stories.tsx']
})
],