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