import { defineConfig } from 'vite'; import tailwindcss from 'tailwindcss'; import autoprefixer from 'autoprefixer'; import path from 'path'; import nesting from 'tailwindcss/nesting'; const isLib = process.env.NODE_MODE === 'lib'; // https://vitejs.dev/config/ const configLib = defineConfig({ plugins: [], css: { postcss: { // @ts-ignore plugins: [nesting, tailwindcss, autoprefixer], }, }, resolve: { alias: { '@': path.resolve(__dirname, './src'), }, }, build: { lib: { entry: 'src/button.ts', // 入口文件,库的主入口 formats: ['es'], // 输出格式 fileName: () => `button.js`, // 输出的文件名 }, minify: true, }, }); const configServer = defineConfig({ plugins: [], base: './', css: { postcss: { // @ts-ignore plugins: [nesting, tailwindcss, autoprefixer], }, }, resolve: { alias: { '@': path.resolve(__dirname, './src'), }, }, build: { minify: false, terserOptions: {}, rollupOptions: { output: { dir: 'dist/docs', assetFileNames: () => { // return 'assets/[name]-[hash].[ext]'; // 其他静态资源仍使用hash return '[name].[ext]'; // 其他静态资源仍使用hash }, entryFileNames: 'index.js', }, }, }, define: { DEV_SERVER: JSON.stringify(process.env.NODE_ENV === 'development'), }, server: { port: 6015, proxy: { '/api': { target: 'http://localhost:3000', changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, '/api'), }, }, }, }); const config = isLib ? configLib : configServer; export default config;