You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.1 KiB

1 month ago
import { resolve } from 'path'
import { defineConfig, loadEnv } from 'vite'
1 month ago
import vue from "@vitejs/plugin-vue2";
import vueJsx from "@vitejs/plugin-vue2-jsx";
1 month ago
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import compressPlugin from 'vite-plugin-compression'
1 month ago
// compress: 'gzip' | 'brotli' | 'none'
function configCompressPlugin(isBuild, compress) {
1 month ago
const plugins = []
if (!isBuild) return plugins
const compressList = compress.split(',')
if (compressList.includes('gzip')) {
1 month ago
plugins.push(
compressPlugin({
verbose: true,
disable: false,
threshold: 10240,
1 month ago
algorithm: 'gzip',
ext: '.gz'
1 month ago
})
1 month ago
)
1 month ago
}
1 month ago
if (compressList.includes('brotli')) {
1 month ago
plugins.push(
compressPlugin({
verbose: true,
disable: false,
threshold: 10240,
1 month ago
algorithm: 'brotliCompress',
ext: '.br'
1 month ago
})
1 month ago
)
1 month ago
}
1 month ago
return plugins
1 month ago
}
1 month ago
export default ({ command, mode }) => {
const isBuild = mode === 'production' // mode == production
const env = loadEnv(mode, process.cwd()) // dev
console.log('env',mode,env);
const port = env.PORT || 9528 // dev port
1 month ago
return defineConfig({
plugins: [
vue(),
vueJsx(),
createSvgIconsPlugin({
1 month ago
iconDirs: [resolve(process.cwd(), 'src/icons/svg')],
symbolId: 'icon-[dir]-[name]'
1 month ago
}),
1 month ago
...configCompressPlugin(isBuild, 'gzip')
1 month ago
],
resolve: {
alias: {
1 month ago
'@': resolve(__dirname, './src'),
vue: 'vue/dist/vue.esm.js',
}
1 month ago
},
1 month ago
base: '/',
1 month ago
server: {
port,
open: true,
1 month ago
host: '0.0.0.0',
1 month ago
hmr: { overlay: false },
proxy: {
1 month ago
'/api': {
rewrite: (path) => path.replace(/^\/api/, ''),
1 month ago
target: env.VITE_APP_BASE_URL,
changeOrigin: true,
1 month ago
ws: true
1 month ago
},
1 month ago
'/wvp': {
rewrite: (path) => path.replace(/^\/wvp/, ''),
target: env.VITE_APP_WVP_URL,
1 month ago
changeOrigin: true,
1 month ago
ws: true
1 month ago
},
1 month ago
'/play': {
rewrite: (path) => path.replace(/^\/play/, '/rtp'),
target: 'http://127.0.0.1:8090',
1 month ago
changeOrigin: true,
1 month ago
ws: true
1 month ago
}
1 month ago
}
1 month ago
},
build: {
1 month ago
outDir: 'dist',
assetsDir: 'static',
sourcemap: false,
chunkSizeWarningLimit: 1000,
1 month ago
rollupOptions: {
output: {
1 month ago
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
// manualChunks(id) { // 静态资源分拆打包
// if (id.includes('node_modules')) {
// return id.toString().split('node_modules/')[1].split('/')[0].toString()
// }
// }
}
1 month ago
},
// minify: 'terser',
// terserOptions: {
// compress: {
// drop_console: isBuild, // 打包时删除log
// drop_debugger: isBuild, // 打包时删除debugger
// pure_funcs: isBuild ? ['console.log'] : []
// },
// output: {
// comments: isBuild // 去掉注释
// }
// }
1 month ago
}
})
}