import {resolve} from 'path' import {defineConfig} from 'vite' import vue from '@vitejs/plugin-vue' import dts from 'vite-plugin-dts' // 为打包的库里加入声明文件(即生成:.d.ts文件) import DefineOptions from "unplugin-vue-define-options/vite"; export default defineConfig({ plugins: [ vue(), // @ts-ignore dts({ // include: ['src/**/*.vue', 'src/**/*.ts'], // 指定需要生成类型声明文件的文件路径 // include: ['src/index.ts'], // 指定需要生成类型声明文件的文件路径 entryRoot: "./src/components", // entryRoot: "./src", // @ts-ignore outputDir: ["/dist"], // 指定使用的tsconfig.json为我们整个项目根目录下,如果不配置,你也可以在components下新建tsconfig.json tsConfigFilePath: "./tsconfig.json", }), DefineOptions() ], // 构建为lib库 build: { lib: { // __dirname的值是vite.config.ts文件所在目录 entry: resolve(__dirname, 'src/index.ts'), name: 'ZcWebComponent', fileName: 'index', }, rollupOptions: { // 该选项用于匹配需要排除在 bundle 外部的模块 external: ['vue', 'configManager', 'pinia'], // input: { // types: resolve(__dirname, 'src/vite-env.d.ts'), // }, // 打包出口:用于指定所有生成包存放目录 output: { exports: 'named', // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量 globals: { vue: 'vue', ConfigManager: 'configManager', pinia: 'pinia' } } }, // minify: 'terser' }, server: { proxy: { '/service': 'https://marketing.zcline.net', } } })