1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import { defineConfig, loadEnv } from 'vite'
- import vue from '@vitejs/plugin-vue'
- import path from 'path'
- import { compression } from 'vite-plugin-compression2'
- export default defineConfig(({ command, mode }) => {
-
- const env = loadEnv(mode, process.cwd())
-
- return {
- plugins: [
- vue(),
-
- env.VITE_USE_COMPRESSION === 'true' && compression({
- algorithm: 'gzip',
- threshold: 1024 * 10
- })
- ],
- resolve: {
- alias: {
- '@': path.resolve(__dirname, 'src')
-
- }
- },
- server: {
- port: 3000,
- proxy: env.VITE_USE_PROXY === 'true' ? {
- [env.VITE_API_BASE_URL]: {
- target: env.VITE_PROXY_TARGET,
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/env.VITE_API_BASE_URL/, '')
- }
- } : null
- },
- css: {
- preprocessorOptions: {
- scss: {
- api: 'modern-compiler',
- additionalData: `@use "@/styles/variables.scss" as *;`
- }
- }
- },
- build: {
-
- outDir: mode === 'production' ? 'dist-prod' : 'dist-test',
-
- assetsDir: 'assets',
-
- assetsInlineLimit: 4096,
-
- cssCodeSplit: true,
-
- sourcemap: mode === 'production',
-
- rollupOptions: {
- input: {
- main: path.resolve(__dirname, 'index.html')
- },
- output: {
-
- chunkFileNames: 'assets/js/[name]-[hash].js',
- entryFileNames: 'assets/js/[name]-[hash].js',
- assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
-
- manualChunks: {
- 'element-plus': ['element-plus'],
- 'vue-lib': ['vue', 'vue-router', 'pinia']
- }
- }
- },
-
- minify: mode === 'production' ? false : 'esbuild',
-
- brotliSize: false,
-
- chunkSizeWarningLimit: 2000
- },
- optimizeDeps: {
- include: ['vue', 'vue-router', 'pinia', 'axios', 'element-plus']
- }
- }
- })
|