first commit
This commit is contained in:
+185
@@ -0,0 +1,185 @@
|
||||
/**
|
||||
* <licenses>
|
||||
* <license>
|
||||
* <name>JeecgBoot商业授权:商业版本只针对企业用户授权,提供更专业更强大的商业版本</name>
|
||||
* <url>http://jeecg.com/vip</url>
|
||||
* <distribution>禁止盗版买卖,违者必究,举报邮箱: jeecgos@163.com</distribution>
|
||||
* <comments>Copyright:北京国炬信息技术有限公司</comments>
|
||||
* </license>
|
||||
* </licenses>
|
||||
* <developers>
|
||||
* <developer>
|
||||
* <name>北京国炬信息技术有限公司</name>
|
||||
* <email>jeecgos@163.com</email>
|
||||
* </developer>
|
||||
* <developer>
|
||||
* <name>授权对象(合作企业): 中国船舶集团有限公司第七〇四研究所</name>
|
||||
* <email>授权范围:贵司通过商业合作,获得商业产品的使用权,但商业版源码、资料禁止传播、盗卖,违者必究!!!</email>
|
||||
* </developer>
|
||||
* </developers>
|
||||
*/
|
||||
|
||||
import type { UserConfig, ConfigEnv } from 'vite';
|
||||
import pkg from './package.json';
|
||||
import dayjs from 'dayjs';
|
||||
import { loadEnv } from 'vite';
|
||||
import { resolve } from 'path';
|
||||
import { generateModifyVars } from './build/generate/generateModifyVars';
|
||||
import { createProxy } from './build/vite/proxy';
|
||||
import { wrapperEnv } from './build/utils';
|
||||
import { createVitePlugins } from './build/vite/plugin';
|
||||
import { OUTPUT_DIR } from './build/constant';
|
||||
|
||||
function pathResolve(dir: string) {
|
||||
return resolve(process.cwd(), '.', dir);
|
||||
}
|
||||
|
||||
const { dependencies, devDependencies, name, version } = pkg;
|
||||
const __APP_INFO__ = {
|
||||
pkg: { dependencies, devDependencies, name, version },
|
||||
lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||
};
|
||||
|
||||
export default ({ command, mode }: ConfigEnv): UserConfig => {
|
||||
const root = process.cwd();
|
||||
|
||||
const env = loadEnv(mode, root);
|
||||
|
||||
// The boolean type read by loadEnv is a string. This function can be converted to boolean type
|
||||
const viteEnv = wrapperEnv(env);
|
||||
|
||||
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY } = viteEnv;
|
||||
|
||||
const isBuild = command === 'build';
|
||||
|
||||
const serverOptions: Recordable = {}
|
||||
|
||||
// ----- [begin] 【JEECG作为乾坤子应用】 -----
|
||||
const {VITE_GLOB_QIANKUN_MICRO_APP_NAME, VITE_GLOB_QIANKUN_MICRO_APP_ENTRY} = viteEnv;
|
||||
const isQiankunMicro = VITE_GLOB_QIANKUN_MICRO_APP_NAME != null && VITE_GLOB_QIANKUN_MICRO_APP_NAME !== '';
|
||||
if (isQiankunMicro && !isBuild) {
|
||||
serverOptions.cors = true;
|
||||
serverOptions.origin = VITE_GLOB_QIANKUN_MICRO_APP_ENTRY!.split('/').slice(0, 3).join('/');
|
||||
}
|
||||
// ----- [end] 【JEECG作为乾坤子应用】 -----
|
||||
|
||||
return {
|
||||
base: isQiankunMicro ? VITE_GLOB_QIANKUN_MICRO_APP_ENTRY : VITE_PUBLIC_PATH,
|
||||
root,
|
||||
resolve: {
|
||||
alias: [
|
||||
{
|
||||
find: 'vue-i18n',
|
||||
replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
|
||||
},
|
||||
// /@/xxxx => src/xxxx
|
||||
{
|
||||
find: /\/@\//,
|
||||
replacement: pathResolve('src') + '/',
|
||||
},
|
||||
// /#/xxxx => types/xxxx
|
||||
{
|
||||
find: /\/#\//,
|
||||
replacement: pathResolve('types') + '/',
|
||||
},
|
||||
{
|
||||
find: /@\//,
|
||||
replacement: pathResolve('src') + '/',
|
||||
},
|
||||
// /#/xxxx => types/xxxx
|
||||
{
|
||||
find: /#\//,
|
||||
replacement: pathResolve('types') + '/',
|
||||
},
|
||||
],
|
||||
},
|
||||
server: {
|
||||
// Listening on all local IPs
|
||||
host: true,
|
||||
// @ts-ignore
|
||||
https: false,
|
||||
port: VITE_PORT,
|
||||
// Load proxy configuration from .env
|
||||
proxy: createProxy(VITE_PROXY),
|
||||
// 合并 server 配置
|
||||
...serverOptions,
|
||||
},
|
||||
build: {
|
||||
minify: 'esbuild',
|
||||
target: 'es2015',
|
||||
cssTarget: 'chrome80',
|
||||
outDir: OUTPUT_DIR,
|
||||
rollupOptions: {
|
||||
// 【QQYUN-6901】【QQYUN-6989】关闭除屑优化,防止删除重要代码,导致打包后功能出现异常
|
||||
treeshake: false,
|
||||
output: {
|
||||
chunkFileNames: 'js/[name]-[hash].js', // 引入文件名的名称
|
||||
entryFileNames: 'js/[name]-[hash].js', // 包的入口文件名称
|
||||
// manualChunks配置 (依赖包从大到小排列)
|
||||
// update-begin--author:liaozhiyang---date:20240308---for:【QQYUN-8241】生产包优化加载
|
||||
manualChunks: {
|
||||
// vue vue-router合并打包
|
||||
'vue-vendor': ['vue', 'vue-router'],
|
||||
'antd-vue-vendor': ['ant-design-vue','@ant-design/icons-vue','@ant-design/colors'],
|
||||
'vxe-table-vendor': ['vxe-table','vxe-table-plugin-antd','xe-utils'],
|
||||
// 'codemirror-vendor': ['codemirror'],
|
||||
'emoji-mart-vue-fast': ['emoji-mart-vue-fast'],
|
||||
// 将 Lodash 库的代码单独打包
|
||||
//'lodash-es-vendor': ['lodash-es'],
|
||||
'html2canvas-vendor': ['html2canvas'],
|
||||
// 'tinymce-vendor': ['tinymce','@tinymce/tinymce-vue'],
|
||||
// 'echarts-vendor': ['echarts'],
|
||||
// 'cron-parser-vendor': ['cron-parser'],
|
||||
// 商业版特有的依赖
|
||||
// 'xlsx-vendor': ['xlsx','xlsx-style-jeecg'],
|
||||
// 'china-area-data-vendor': ['china-area-data'],
|
||||
'fullcalendar-vendor': ['@fullcalendar/vue3','@fullcalendar/core','@fullcalendar/daygrid','@fullcalendar/interaction','@fullcalendar/timegrid','@fullcalendar/resource-timeline'],
|
||||
'pinyin-pro-vendor': ['pinyin-pro'],
|
||||
// 'jspdf-vendor': ['jspdf'],
|
||||
'bpmn-js-vendor': ['bpmn-js'],
|
||||
'vuedraggable-vendor': ['vuedraggable'],
|
||||
},
|
||||
// update-begin--author:liaozhiyang---date:20240308---for:【QQYUN-8241】生产包优化加载
|
||||
}
|
||||
},
|
||||
// 关闭brotliSize显示可以稍微减少打包时间
|
||||
reportCompressedSize: false,
|
||||
// 提高超大静态资源警告大小
|
||||
chunkSizeWarningLimit: 2000,
|
||||
},
|
||||
esbuild: {
|
||||
//清除全局的console.log和debug
|
||||
drop: isBuild ? ['console', 'debugger'] : [],
|
||||
},
|
||||
define: {
|
||||
// setting vue-i18-next
|
||||
// Suppress warning
|
||||
__INTLIFY_PROD_DEVTOOLS__: false,
|
||||
__APP_INFO__: JSON.stringify(__APP_INFO__),
|
||||
},
|
||||
css: {
|
||||
preprocessorOptions: {
|
||||
less: {
|
||||
modifyVars: generateModifyVars(),
|
||||
javascriptEnabled: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// The vite plugin used by the project. The quantity is large, so it is separately extracted and managed
|
||||
plugins: createVitePlugins(viteEnv, isBuild, isQiankunMicro),
|
||||
|
||||
optimizeDeps: {
|
||||
esbuildOptions: {
|
||||
target: 'es2020',
|
||||
},
|
||||
// @iconify/iconify: The dependency is dynamically and virtually loaded by @purge-icons/generated, so it needs to be specified explicitly
|
||||
include: [
|
||||
'@vue/shared',
|
||||
'@iconify/iconify',
|
||||
'ant-design-vue/es/locale/zh_CN',
|
||||
'ant-design-vue/es/locale/en_US',
|
||||
],
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user