20261007220117
This commit is contained in:
1 parent
9217b3fa42
commit
8b1ec67609
275 files changed
+20026
-49299
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import { defineConfig } from 'vite'
|
||||
import dts from 'vite-plugin-dts'
|
||||
|
||||
/**
|
||||
* 组件库构建:产出 ESM + 类型声明。
|
||||
*
|
||||
* 关键点:
|
||||
* - vue 必须外置(external),否则包里会打进一份 Vue,消费方出现双实例
|
||||
* - preserveModules 保留源码结构,消费方能按需 tree-shaking
|
||||
* - vite-plugin-dts 生成 dist/index.d.ts,配合 package.json 的 exports.types
|
||||
*/
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
vue(),
|
||||
dts({
|
||||
// 只产出声明文件,JS 交给 vite 本体
|
||||
include: ['src'],
|
||||
outDir: 'dist',
|
||||
rollupTypes: true,
|
||||
}),
|
||||
],
|
||||
build: {
|
||||
lib: {
|
||||
entry: fileURLToPath(new URL('./src/index.ts', import.meta.url)),
|
||||
formats: ['es'],
|
||||
fileName: () => 'index.js',
|
||||
},
|
||||
rollupOptions: {
|
||||
external: ['vue'],
|
||||
output: {
|
||||
preserveModules: true,
|
||||
preserveModulesRoot: 'src',
|
||||
entryFileNames: '[name].js',
|
||||
assetFileNames: 'style.css',
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in new issue
Block a user