98 lines
2.8 KiB
JavaScript
98 lines
2.8 KiB
JavaScript
import { fileURLToPath, URL } from 'node:url'
|
||
|
||
import { defineConfig, loadEnv } from 'vite'
|
||
import vue from '@vitejs/plugin-vue'
|
||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||
import vueDevTools from 'vite-plugin-vue-devtools'
|
||
|
||
import Components from 'unplugin-vue-components/vite'
|
||
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
|
||
import { createHtmlPlugin } from 'vite-plugin-html'
|
||
import viteCompression from 'vite-plugin-compression'
|
||
|
||
import { viteStaticCopy } from 'vite-plugin-static-copy'
|
||
|
||
// https://vite.dev/config/
|
||
export default defineConfig(({ mode }) => {
|
||
// eslint-disable-next-line no-undef
|
||
const env = loadEnv(mode, process.cwd())
|
||
|
||
// 生产环境复制 Amis 的 SDK,开发环境按需引用
|
||
let copes = [{ src: 'node_modules/amis/sdk/*', dest: 'assets' }]
|
||
if (mode === 'development')
|
||
copes.push({ src: 'node_modules/amis/sdk/*', dest: 'node_modules/.vite/deps' })
|
||
|
||
return {
|
||
base: './',
|
||
build: {
|
||
emptyOutDir: true,
|
||
manifest: true,
|
||
outDir: '../src/main/resources/static/manager-ui',
|
||
rollupOptions: {
|
||
output: {
|
||
manualChunks(id) {
|
||
if (id.includes('node_modules')) {
|
||
if (id.includes('ant-design-vue')) {
|
||
return 'ant-design-vue'
|
||
} else if (id.includes('dayjs')) {
|
||
return 'dayjs'
|
||
} else if (id.includes('lodash')) {
|
||
return 'lodash'
|
||
} else if (id.includes('tree-lodash')) {
|
||
return 'tree-lodash'
|
||
} else if (id.includes('vue-request')) {
|
||
return 'vue-request'
|
||
} else if (id.includes('js-cookie')) {
|
||
return 'js-cookie'
|
||
} else if (id.includes('jsencrypt')) {
|
||
return 'jsencrypt'
|
||
} else if (id.includes('jwt-decode')) {
|
||
return 'jwt-decode'
|
||
} else {
|
||
return 'vendor'
|
||
}
|
||
} else {
|
||
return undefined
|
||
}
|
||
},
|
||
},
|
||
},
|
||
},
|
||
plugins: [
|
||
vue(),
|
||
vueJsx(),
|
||
viteCompression({ threshold: 1024 * 300 }),
|
||
vueDevTools(),
|
||
Components({
|
||
resolvers: [
|
||
AntDesignVueResolver({
|
||
importStyle: false, // css in js
|
||
}),
|
||
],
|
||
}),
|
||
createHtmlPlugin({
|
||
inject: {
|
||
data: {
|
||
VITE_APP_TITLE: env.VITE_APP_TITLE,
|
||
},
|
||
},
|
||
}),
|
||
viteStaticCopy({ targets: copes }),
|
||
],
|
||
server: {
|
||
proxy: {
|
||
'/api': {
|
||
target: 'http://localhost:8080',
|
||
changeOrigin: true,
|
||
rewrite: (path) => path.replace(/^\/api/, ''),
|
||
},
|
||
},
|
||
},
|
||
resolve: {
|
||
alias: {
|
||
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||
},
|
||
},
|
||
}
|
||
})
|