vite 开发库配置
vite.config.ts
`
1 | import path from 'path' |
2 | import { defineConfig, UserConfigExport, ConfigEnv } from 'vite' |
3 | import dts from 'vite-plugin-dts' |
4 | |
5 | // https://vitejs.dev/config/ |
6 | const config = ({ command, mode }: ConfigEnv): UserConfigExport => { |
7 | return defineConfig({ |
8 | build: { |
9 | target: 'es2015', |
10 | outDir: 'dist', |
11 | lib: { |
12 | entry: path.resolve(__dirname, './src/main.ts'), |
13 | name: 'MyLib', |
14 | fileName: `my-lib` |
15 | }, |
16 | rollupOptions: { |
17 | output: { |
18 | // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量 |
19 | globals: { |
20 | MyLib: 'MyLib' |
21 | } |
22 | } |
23 | } |
24 | }, |
25 | plugins: [ |
26 | // 自动构建.d.ts |
27 | dts({ |
28 | insertTypesEntry: true, |
29 | copyDtsFiles: false |
30 | }) |
31 | ] |
32 | }) |
33 | } |
34 | |
35 | export default config |