123456789101112131415161718192021222324252627282930313233343536 |
- import { defineConfig } from 'vite';
- import vue from '@vitejs/plugin-vue';
- import VitePluginStyleInject from 'vite-plugin-style-inject';
- // 获取环境变量中的组件名称
- const componentName = process.env.name;
- console.log('当前组件名称:', componentName)
- export default defineConfig({
- plugins: [
- vue(), // 添加 Vue 插件
- VitePluginStyleInject() // 添加样式注入插件
- ],
- build: {
- lib: {
- entry: 'index.js', // 入口文件
- name: 'MyComponentLibrary', // 全局变量名
- fileName: (format) => `index.${format}.js`, // 输出文件名
- },
- rollupOptions: {
- external: ['vue'], // 外部依赖
- output: {
- globals: {
- vue: 'Vue'
- },
- },
- input: componentName
- ? {
- [componentName]: `./${componentName}/index.js`,
- }
- : {},
- },
- outDir: `./${componentName}/dist`,
- },
- });
|