80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
|
import { ConfigEnv, defineConfig, loadEnv } from 'vite';
|
||
|
import vue from '@vitejs/plugin-vue';
|
||
|
import path from 'path';
|
||
|
import tailwindcss from 'tailwindcss';
|
||
|
// import { viteMockServe } from 'vite-plugin-mock';
|
||
|
import autoGenerateVue from './plugins/vite-plugin-auto-generate-vue';
|
||
|
import svgLoader from 'vite-svg-loader';
|
||
|
import autoImportDTS from '@skyfox2000/vite-plugin-auto-import-dts';
|
||
|
import rollupPluginGzip from 'rollup-plugin-gzip';
|
||
|
import { visualizer } from 'rollup-plugin-visualizer';
|
||
|
|
||
|
// https://vitejs.dev/config/
|
||
|
// @ts-ignore
|
||
|
export default defineConfig(({ mode }: ConfigEnv) => {
|
||
|
const root = process.cwd();
|
||
|
const env = loadEnv(mode, root);
|
||
|
console.log(env);
|
||
|
|
||
|
return {
|
||
|
plugins: [
|
||
|
autoImportDTS({
|
||
|
path: './src/views',
|
||
|
}),
|
||
|
autoGenerateVue({
|
||
|
dir: './src/components',
|
||
|
output: './src/components/index.ts',
|
||
|
}),
|
||
|
vue(),
|
||
|
svgLoader(),
|
||
|
visualizer({
|
||
|
emitFile: false,
|
||
|
filename: './node_modules/.tmp/visualizer.html',
|
||
|
open: false,
|
||
|
}),
|
||
|
rollupPluginGzip(),
|
||
|
],
|
||
|
esmExternals: true,
|
||
|
css: {
|
||
|
postcss: {
|
||
|
plugins: [tailwindcss()],
|
||
|
},
|
||
|
},
|
||
|
resolve: {
|
||
|
alias: {
|
||
|
'@': path.resolve(__dirname, './src'),
|
||
|
},
|
||
|
extensions: ['.js', '.ts', '.vue', 'json'],
|
||
|
},
|
||
|
base: '/',
|
||
|
build: {
|
||
|
outDir: 'dist',
|
||
|
assetsDir: 'assets',
|
||
|
rollupOptions: {
|
||
|
treeshake: {
|
||
|
moduleSideEffects: false, // 移除无副作用的模块
|
||
|
},
|
||
|
output: {
|
||
|
entryFileNames: 'static/index/[name]-[hash].js',
|
||
|
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
|
||
|
chunkFileNames: (assetInfo) => {
|
||
|
let name = assetInfo.name;
|
||
|
if (name.indexOf('.') > -1) name = name.substring(0, name.indexOf('.'));
|
||
|
return `assets/modules/${name}-[hash].js`;
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
// 复制 assets 目录到 outDir
|
||
|
assetsInclude: ['assets/**/*'],
|
||
|
minify: true, // 开启压缩
|
||
|
sourcemap: false,
|
||
|
},
|
||
|
devServer: {
|
||
|
headers: {
|
||
|
'Access-Control-Allow-Origin': '*',
|
||
|
},
|
||
|
},
|
||
|
server: {},
|
||
|
};
|
||
|
});
|