blossom/blossom-web/vite.config.ts

83 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-08-07 11:50:22 +08:00
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import { visualizer } from 'rollup-plugin-visualizer'
2023-08-07 11:50:22 +08:00
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
// 为 Element Plus 按需引入样式。
import ElementPlus from 'unplugin-element-plus/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { resolve } from 'path'
const npm_lifecycle_event = process.env.npm_lifecycle_event
const isSpring = () => {
return npm_lifecycle_event && npm_lifecycle_event === 'build:spring'
}
console.log('当前运行脚本: ', npm_lifecycle_event)
2023-08-07 11:50:22 +08:00
// https://vitejs.dev/config/
export default defineConfig({
base: './',
envDir: resolve('env'),
2023-08-07 11:50:22 +08:00
server: {
host: '0.0.0.0',
2023-08-07 11:50:22 +08:00
port: 5174,
hmr: true
},
plugins: [
vue(),
vueJsx(),
visualizer({
emitFile: false,
filename: 'stats.html', // 分析图生成的文件名
2023-08-07 11:50:22 +08:00
open: true //如果存在本地服务端口,将在打包后自动展示
}),
// ElementPlus 按需引入的插件
AutoImport({
resolvers: [ElementPlusResolver()]
2023-08-07 11:50:22 +08:00
}),
Components({
resolvers: [ElementPlusResolver()]
2023-08-07 11:50:22 +08:00
}),
ElementPlus({
// options
})
2023-08-07 11:50:22 +08:00
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
css: {
preprocessorOptions: {
scss: {
/**
* 使
2023-08-07 11:50:22 +08:00
* '@import "@/assets/scss/globalVariable1.scss";
* @import"@/assets/scss/globalVariable2.scss";'
*/
additionalData: '@import "@/assets/styles/config.scss";'
2023-08-07 11:50:22 +08:00
}
}
},
build: {
outDir: isSpring() ? '../blossom-backend/backend/src/main/resources/static/blog' : 'dist',
2023-08-07 11:50:22 +08:00
// 警告大小, 单位kb
// chunkSizeWarningLimit: 1000,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
return id.toString().split('node_modules/')[1].split('/')[0].toString()
2023-08-07 11:50:22 +08:00
}
}
}
}
}
})