build: 🔨 打包优化

This commit is contained in:
Bunny 2024-10-26 02:31:35 +08:00
parent 6b88a7b154
commit 72d16ef29e
5 changed files with 86 additions and 2312 deletions

View File

@ -23,7 +23,7 @@ VITE_BASE_API_RETRY=5
VITE_BASE_API_RETRY_DELAY=3000 VITE_BASE_API_RETRY_DELAY=3000
# 是否在打包时使用cdn替换本地库 替换 true 不替换 false # 是否在打包时使用cdn替换本地库 替换 true 不替换 false
VITE_CDN=false VITE_CDN=true
# 是否启用gzip压缩或brotli压缩分两种情况删除原始文件和不删除原始文件 # 是否启用gzip压缩或brotli压缩分两种情况删除原始文件和不删除原始文件
# 压缩时不删除原始文件的配置gzip、brotli、both同时开启 gzip 与 brotli 压缩、none不开启压缩默认 # 压缩时不删除原始文件的配置gzip、brotli、both同时开启 gzip 与 brotli 压缩、none不开启压缩默认

View File

@ -1,4 +1,4 @@
import { Plugin as importToCDN } from "vite-plugin-cdn-import"; import { Plugin as importToCDN } from 'vite-plugin-cdn-import';
/** /**
* @description `cdn`使cdn模式 .env.production VITE_CDN true * @description `cdn`使cdn模式 .env.production VITE_CDN true
@ -6,55 +6,55 @@ import { Plugin as importToCDN } from "vite-plugin-cdn-import";
* 使jscss文件cdn * 使jscss文件cdn
*/ */
export const cdn = importToCDN({ export const cdn = importToCDN({
//prodUrl解释 name: 对应下面modules的nameversion: 自动读取本地package.json中dependencies依赖中对应包的版本号path: 对应下面modules的path当然也可写完整路径会替换prodUrl //prodUrl解释 name: 对应下面modules的nameversion: 自动读取本地package.json中dependencies依赖中对应包的版本号path: 对应下面modules的path当然也可写完整路径会替换prodUrl
prodUrl: "https://cdn.bootcdn.net/ajax/libs/{name}/{version}/{path}", prodUrl: 'https://cdn.bootcdn.net/ajax/libs/{name}/{version}/{path}',
modules: [ modules: [
{ {
name: "vue", name: 'vue',
var: "Vue", var: 'Vue',
path: "vue.global.prod.min.js" path: 'vue.global.prod.min.js',
}, },
{ {
name: "vue-router", name: 'vue-router',
var: "VueRouter", var: 'VueRouter',
path: "vue-router.global.min.js" path: 'vue-router.global.min.js',
}, },
{ {
name: "vue-i18n", name: 'vue-i18n',
var: "VueI18n", var: 'VueI18n',
path: "vue-i18n.runtime.global.prod.min.js" path: 'vue-i18n.runtime.global.prod.min.js',
}, },
// 项目中没有直接安装vue-demi但是pinia用到了所以需要在引入pinia前引入vue-demihttps://github.com/vuejs/pinia/blob/v2/packages/pinia/package.json#L77 // 项目中没有直接安装vue-demi但是pinia用到了所以需要在引入pinia前引入vue-demihttps://github.com/vuejs/pinia/blob/v2/packages/pinia/package.json#L77
{ {
name: "vue-demi", name: 'vue-demi',
var: "VueDemi", var: 'VueDemi',
path: "index.iife.min.js" path: 'index.iife.min.js',
}, },
{ {
name: "pinia", name: 'pinia',
var: "Pinia", var: 'Pinia',
path: "pinia.iife.min.js" path: 'pinia.iife.min.js',
}, },
{ {
name: "element-plus", name: 'element-plus',
var: "ElementPlus", var: 'ElementPlus',
path: "index.full.min.js", path: 'index.full.min.js',
css: "index.min.css" css: 'index.min.css',
}, },
{ {
name: "axios", name: 'axios',
var: "axios", var: 'axios',
path: "axios.min.js" path: 'axios.min.js',
}, },
{ {
name: "dayjs", name: 'dayjs',
var: "dayjs", var: 'dayjs',
path: "dayjs.min.js" path: 'dayjs.min.js',
}, },
{ // {
name: "echarts", // name: "echarts",
var: "echarts", // var: "echarts",
path: "echarts.min.js" // path: "echarts.min.js"
} // }
] ],
}); });

View File

@ -51,9 +51,6 @@
"dependencies": { "dependencies": {
"@amap/amap-jsapi-loader": "^1.0.1", "@amap/amap-jsapi-loader": "^1.0.1",
"@howdyjs/mouse-menu": "^2.1.3", "@howdyjs/mouse-menu": "^2.1.3",
"@infectoone/vue-ganttastic": "^2.3.2",
"@logicflow/core": "^1.2.27",
"@logicflow/extension": "^1.2.27",
"@pureadmin/descriptions": "^1.2.1", "@pureadmin/descriptions": "^1.2.1",
"@pureadmin/table": "^3.1.2", "@pureadmin/table": "^3.1.2",
"@pureadmin/utils": "^2.4.7", "@pureadmin/utils": "^2.4.7",
@ -61,8 +58,6 @@
"@vue-flow/core": "^1.33.6", "@vue-flow/core": "^1.33.6",
"@vueuse/core": "^10.9.0", "@vueuse/core": "^10.9.0",
"@vueuse/motion": "^2.1.0", "@vueuse/motion": "^2.1.0",
"@wangeditor/editor": "^5.1.23",
"@wangeditor/editor-for-vue": "^5.1.12",
"@zxcvbn-ts/core": "^3.0.4", "@zxcvbn-ts/core": "^3.0.4",
"animate.css": "^4.1.1", "animate.css": "^4.1.1",
"axios": "^1.6.8", "axios": "^1.6.8",
@ -70,7 +65,6 @@
"cropperjs": "^1.6.2", "cropperjs": "^1.6.2",
"dayjs": "^1.11.11", "dayjs": "^1.11.11",
"echarts": "^5.5.0", "echarts": "^5.5.0",
"echarts-gl": "^2.0.9",
"el-table-infinite-scroll": "^3.0.3", "el-table-infinite-scroll": "^3.0.3",
"element-plus": "2.7.1", "element-plus": "2.7.1",
"intro.js": "^7.2.0", "intro.js": "^7.2.0",

File diff suppressed because it is too large Load Diff

View File

@ -1,32 +1,31 @@
import { getPluginsList } from "./build/plugins"; import { getPluginsList } from './build/plugins';
import { exclude, include } from "./build/optimize"; import { exclude, include } from './build/optimize';
import { type ConfigEnv, loadEnv, type UserConfigExport } from "vite"; import { type ConfigEnv, loadEnv, type UserConfigExport } from 'vite';
import { __APP_INFO__, alias, root, wrapperEnv } from "./build/utils"; import { __APP_INFO__, alias, root, wrapperEnv } from './build/utils';
import { serverOptions } from "./build/server"; import { serverOptions } from './build/server';
import { buildEnvironment } from "./build/buildEnv"; import { buildEnvironment } from './build/buildEnv';
export default ({ mode }: ConfigEnv): UserConfigExport => { export default ({ mode }: ConfigEnv): UserConfigExport => {
const { VITE_CDN, VITE_PORT, VITE_COMPRESSION, VITE_PUBLIC_PATH } = const { VITE_CDN, VITE_PORT, VITE_COMPRESSION, VITE_PUBLIC_PATH } = wrapperEnv(loadEnv(mode, root));
wrapperEnv(loadEnv(mode, root)); return {
return { base: VITE_PUBLIC_PATH,
base: VITE_PUBLIC_PATH, root,
root, resolve: { alias },
resolve: { alias }, // 服务端渲染
// 服务端渲染 server: serverOptions(mode),
server: serverOptions(mode), plugins: getPluginsList(VITE_CDN, VITE_COMPRESSION, VITE_PORT),
plugins: getPluginsList(VITE_CDN, VITE_COMPRESSION, VITE_PORT), // https://cn.vitejs.dev/config/dep-optimization-options.html#dep-optimization-options
// https://cn.vitejs.dev/config/dep-optimization-options.html#dep-optimization-options optimizeDeps: { include, exclude },
optimizeDeps: { include, exclude }, esbuild: {
esbuild: { pure: ['console.log', 'debugger'],
pure: ["console.log", "debugger"], jsxFactory: 'h',
jsxFactory: "h", jsxFragment: 'Fragment',
jsxFragment: "Fragment", jsxInject: "import { h } from 'vue';",
jsxInject: "import { h } from 'vue';" },
}, build: buildEnvironment(),
build: buildEnvironment(), define: {
define: { __INTLIFY_PROD_DEVTOOLS__: false,
__INTLIFY_PROD_DEVTOOLS__: false, __APP_INFO__: JSON.stringify(__APP_INFO__),
__APP_INFO__: JSON.stringify(__APP_INFO__) },
} };
};
}; };