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

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