2025-04-07 14:01:07 +08:00
|
|
|
|
/*
|
|
|
|
|
|
* vite配置
|
|
|
|
|
|
*
|
2025-05-21 15:52:15 +08:00
|
|
|
|
* @Author: YouChain:HouJin
|
2025-04-07 14:01:07 +08:00
|
|
|
|
* @Date: 2022-05-02 23:44:56
|
2025-05-21 15:52:15 +08:00
|
|
|
|
* @Email: huoj@youchain56.com
|
|
|
|
|
|
* @Copyright YouChain ( https://YouChain56.com),Since 2012
|
2025-04-07 14:01:07 +08:00
|
|
|
|
*/
|
|
|
|
|
|
import { resolve } from 'path';
|
|
|
|
|
|
import vue from '@vitejs/plugin-vue';
|
|
|
|
|
|
import customVariables from '/@/theme/custom-variables';
|
2025-05-22 10:03:34 +08:00
|
|
|
|
import * as fs from "node:fs";
|
2025-04-07 14:01:07 +08:00
|
|
|
|
|
|
|
|
|
|
const pathResolve = (dir) => {
|
|
|
|
|
|
return resolve(__dirname, '.', dir);
|
|
|
|
|
|
};
|
|
|
|
|
|
export default {
|
|
|
|
|
|
base: process.env.NODE_ENV === 'production' ? '/' : '/',
|
|
|
|
|
|
root: process.cwd(),
|
|
|
|
|
|
resolve: {
|
|
|
|
|
|
alias: [
|
|
|
|
|
|
// 国际化替换
|
|
|
|
|
|
{
|
|
|
|
|
|
find: 'vue-i18n',
|
|
|
|
|
|
replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
|
|
|
|
|
|
},
|
|
|
|
|
|
// 绝对路径重命名:/@/xxxx => src/xxxx
|
|
|
|
|
|
{
|
|
|
|
|
|
find: /\/@\//,
|
|
|
|
|
|
replacement: pathResolve('src') + '/',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
find: /^~/,
|
|
|
|
|
|
replacement: '',
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
// 服务端渲染
|
|
|
|
|
|
server: {
|
2025-05-22 10:03:34 +08:00
|
|
|
|
https: {
|
|
|
|
|
|
key: fs.readFileSync('./server.key'),
|
|
|
|
|
|
cert: fs.readFileSync('./server.crt'),
|
|
|
|
|
|
},
|
2025-04-07 14:01:07 +08:00
|
|
|
|
host: '0.0.0.0',
|
2025-05-22 10:03:34 +08:00
|
|
|
|
port: 8080,
|
|
|
|
|
|
proxy: {
|
|
|
|
|
|
'/api': {
|
|
|
|
|
|
target: 'https://localhost:8000',
|
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
|
secure: false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-07 14:01:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
plugins: [vue()],
|
|
|
|
|
|
optimizeDeps: {
|
|
|
|
|
|
include: ['ant-design-vue/es/locale/zh_CN', 'dayjs/locale/zh-cn', 'ant-design-vue/es/locale/en_US'],
|
|
|
|
|
|
exclude: ['vue-demi'],
|
|
|
|
|
|
},
|
|
|
|
|
|
build: {
|
|
|
|
|
|
// 清除console和debugger
|
|
|
|
|
|
terserOptions: {
|
|
|
|
|
|
compress: {
|
|
|
|
|
|
drop_console: true,
|
|
|
|
|
|
drop_debugger: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
|
output: {
|
|
|
|
|
|
//配置这个是让不同类型文件放在不同文件夹,不会显得太乱
|
|
|
|
|
|
chunkFileNames: 'js/[name]-[hash].js',
|
|
|
|
|
|
entryFileNames: 'js/[name]-[hash].js',
|
|
|
|
|
|
assetFileNames: '[ext]/[name]-[hash].[ext]',
|
|
|
|
|
|
manualChunks(id) {
|
|
|
|
|
|
//静态资源分拆打包
|
|
|
|
|
|
if (id.includes('node_modules')) {
|
|
|
|
|
|
return id.toString().split('node_modules/')[1].split('/')[0].toString();
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
target: 'esnext',
|
|
|
|
|
|
outDir: 'dist', // 指定输出路径
|
|
|
|
|
|
assetsDir: 'assets', // 指定生成静态文件目录
|
|
|
|
|
|
assetsInlineLimit: '4096', // 小于此阈值的导入或引用资源将内联为 base64 编码
|
|
|
|
|
|
chunkSizeWarningLimit: 500, // chunk 大小警告的限制
|
|
|
|
|
|
minify: 'terser', // 混淆器,terser构建后文件体积更小
|
|
|
|
|
|
emptyOutDir: true, //打包前先清空原有打包文件
|
|
|
|
|
|
},
|
|
|
|
|
|
css: {
|
|
|
|
|
|
preprocessorOptions: {
|
|
|
|
|
|
less: {
|
|
|
|
|
|
modifyVars: customVariables,
|
|
|
|
|
|
javascriptEnabled: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
define: {
|
|
|
|
|
|
__INTLIFY_PROD_DEVTOOLS__: false,
|
|
|
|
|
|
'process.env': process.env,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|