optimize: ♻️ main.ts中引入多语言,路由打包上线加载不出页面,打包配置修改
This commit is contained in:
parent
bf9ff0206e
commit
fe70679ea2
5
.env
5
.env
|
@ -1,3 +1,2 @@
|
||||||
# 请求api地址:process.env.VUE_APP_URL
|
# 请求api地址
|
||||||
VUE_APP_URL=http://localhost:8088/xxx
|
BUNNY_APP_URL=http://localhost:8088/xxx
|
||||||
VUE_APP_FLAG = 'prod'
|
|
||||||
|
|
|
@ -1,15 +1,2 @@
|
||||||
# 本地环境
|
# 请求api地址
|
||||||
VITE_USER_NODE_ENV = development
|
BUNNY_APP_URL=http://localhost:8088/development
|
||||||
|
|
||||||
# 公共基础路径
|
|
||||||
VITE_PUBLIC_PATH = /
|
|
||||||
|
|
||||||
# 是否开启 VitePWA
|
|
||||||
VITE_PWA = false
|
|
||||||
|
|
||||||
# 打包时是否删除 console
|
|
||||||
VITE_DROP_CONSOLE = true
|
|
||||||
|
|
||||||
# 开发环境接口地址
|
|
||||||
VITE_API_URL = /api
|
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,2 @@
|
||||||
# 线上环境
|
# 请求api地址
|
||||||
VITE_USER_NODE_ENV = production
|
BUNNY_APP_URL=http://localhost:8088/prod
|
||||||
|
|
||||||
# 公共基础路径
|
|
||||||
VITE_PUBLIC_PATH = /
|
|
||||||
|
|
||||||
# 是否启用 gzip 或 brotli 压缩打包,如果需要多个压缩规则,可以使用 “,” 分隔
|
|
||||||
# Optional: gzip | brotli | none
|
|
||||||
VITE_BUILD_COMPRESS = none
|
|
||||||
|
|
||||||
# 打包压缩后是否删除源文件
|
|
||||||
VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE = false
|
|
||||||
|
|
||||||
# 打包时是否删除 console
|
|
||||||
VITE_DROP_CONSOLE = true
|
|
||||||
|
|
||||||
# 线上环境接口地址
|
|
||||||
VITE_API_URL = " https://mock.mengxuegu.com/mock/64112a1afe77f949bc0d6ec6/antd"
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
NODE_ENV = 'production'
|
|
||||||
# 请求api地址:process.env.VUE_APP_URL
|
|
||||||
VUE_APP_URL=http://localhost:8088/xxx
|
|
||||||
VUE_APP_FLAG = 'test'
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,9 +9,7 @@
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"serve": "vite",
|
"serve": "vite",
|
||||||
"start": "vite",
|
"start": "vite",
|
||||||
"build:dev": "vue-tsc --noEmit && vite build --mode development",
|
"build": "vite build",
|
||||||
"build:test": "vue-tsc --noEmit && vite build --mode test",
|
|
||||||
"build:pro": "vue-tsc --noEmit && vite build --mode production",
|
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"lint:eslint": "eslint --fix --ext .js,.ts,.vue ./src",
|
"lint:eslint": "eslint --fix --ext .js,.ts,.vue ./src",
|
||||||
"lint:prettier": "prettier --write --loglevel warn \"src/**/*.{js,ts,json,tsx,css,less,scss,vue,html,md}\"",
|
"lint:prettier": "prettier --write --loglevel warn \"src/**/*.{js,ts,json,tsx,css,less,scss,vue,html,md}\"",
|
||||||
|
@ -38,6 +36,7 @@
|
||||||
"pinia-plugin-persistedstate": "^3.2.1",
|
"pinia-plugin-persistedstate": "^3.2.1",
|
||||||
"stylelint-scss": "^6.3.0",
|
"stylelint-scss": "^6.3.0",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
|
"vite-plugin-compression2": "^1.1.1",
|
||||||
"vue": "^3.4.21",
|
"vue": "^3.4.21",
|
||||||
"vue-cookies": "^1.8.3",
|
"vue-cookies": "^1.8.3",
|
||||||
"vue-i18n": "^9.13.1",
|
"vue-i18n": "^9.13.1",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { statisticRoutes } from '@/router/module/statisticRoutes';
|
import { statisticRoutes } from '@/router/module/statisticRoutes';
|
||||||
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router';
|
import { createRouter, createWebHistory } from 'vue-router';
|
||||||
import { pageRoutes } from './module/pageRoutes';
|
import { pageRoutes } from './module/pageRoutes';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,11 +7,7 @@ import { pageRoutes } from './module/pageRoutes';
|
||||||
* * 如果不需要 createWebHistory
|
* * 如果不需要 createWebHistory
|
||||||
*/
|
*/
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history:
|
history: createWebHistory(import.meta.env.BASE_URL), // createWebHashHistory()
|
||||||
process.env.NODE_ENV === 'production'
|
|
||||||
? createWebHashHistory(import.meta.env.BASE_URL)
|
|
||||||
: createWebHistory(import.meta.env.BASE_URL),
|
|
||||||
routes: [...pageRoutes, ...statisticRoutes],
|
routes: [...pageRoutes, ...statisticRoutes],
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
|
@ -26,7 +26,7 @@ function buildRouteTree(context: any, isIndex: boolean, route: any) {
|
||||||
const childrenRoute: any = {
|
const childrenRoute: any = {
|
||||||
name: childrenFileInfo?.name,
|
name: childrenFileInfo?.name,
|
||||||
path: childrenFileInfo!.path,
|
path: childrenFileInfo!.path,
|
||||||
component: isIndex ? () => import(/* @vite-ignore */ `@/views${childrenFileInfo?.replaceName}`) : undefined,
|
component: isIndex ? context[filePath] : undefined,
|
||||||
children: [],
|
children: [],
|
||||||
meta: { isFullScreen: false },
|
meta: { isFullScreen: false },
|
||||||
};
|
};
|
||||||
|
@ -49,7 +49,7 @@ const createRouteList = (context: any, isIndex: boolean) => {
|
||||||
const route: any = {
|
const route: any = {
|
||||||
name: fileInfo?.name,
|
name: fileInfo?.name,
|
||||||
path: fileInfo!.path,
|
path: fileInfo!.path,
|
||||||
component: isIndex ? () => import(/* @vite-ignore */ fileInfo!.filePath, {}) : undefined,
|
component: isIndex ? context[filePath] : undefined,
|
||||||
children: [],
|
children: [],
|
||||||
meta: { isFullScreen: false },
|
meta: { isFullScreen: false },
|
||||||
};
|
};
|
||||||
|
|
|
@ -61,19 +61,21 @@ export const handleDateType = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 得到开始和结束日期,得到中间所有天返回数组
|
* 得到开始和结束日期,得到中间所有天返回数组
|
||||||
* @param {String} string 开始日期'2021-7-1'
|
* @param {String} startDay 开始日期'2021-7-1'
|
||||||
* @param {String} String 结束日期'2021-8-1'
|
* @param {String} endDay 结束日期'2021-8-1'
|
||||||
* @return {Array} ['2021-07-01', '2021-07-01'...., '2021-08-01']
|
* @return {Array} ['2021-07-01', '2021-07-01'...., '2021-08-01']
|
||||||
*/
|
*/
|
||||||
export function getDayArr(startDay: string, endDay: string): Array<string> {
|
export function getDayArr(startDay: string, endDay: string): Array<string> {
|
||||||
let startVal = moment(new Date(startDay)).format('YYYY-MM-DD');
|
let startVal = moment(new Date(startDay)).format('YYYY-MM-DD');
|
||||||
const dayArr = [];
|
const dayArr = [];
|
||||||
while (moment(startVal).isBefore(endDay)) {
|
while (moment(startVal).isBefore(endDay)) {
|
||||||
|
// @ts-expect-error
|
||||||
dayArr.push(moment(new Date(startVal)).format('DD'));
|
dayArr.push(moment(new Date(startVal)).format('DD'));
|
||||||
// 自增
|
// 自增
|
||||||
startVal = moment(new Date(startVal)).add(1, 'day').format('YYYY-MM-DD');
|
startVal = moment(new Date(startVal)).add(1, 'day').format('YYYY-MM-DD');
|
||||||
}
|
}
|
||||||
// 将结束日期的天放进数组
|
// 将结束日期的天放进数组
|
||||||
|
// @ts-expect-error
|
||||||
dayArr.push(moment(new Date(endDay)).format('DD'));
|
dayArr.push(moment(new Date(endDay)).format('DD'));
|
||||||
return dayArr;
|
return dayArr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
const route = {
|
const route = {
|
||||||
|
name: 'my-route',
|
||||||
meta: { isFullScreen: true },
|
meta: { isFullScreen: true },
|
||||||
children: [
|
children: [
|
||||||
{ name: 'bunny_my_a', path: '/bunny/my/a', component: () => import('@/views/bunny/www/index.vue') },
|
{ name: 'bunny_my_a', path: '/bunny/my/a', component: () => import('@/views/bunny/www/index.vue') },
|
||||||
{ name: 'bunny_my_a111', path: '/bunny/my/a/children', component: () => import('@/views/bunny/my/a/aChildren.vue') },
|
{
|
||||||
|
name: 'bunny_my_a111',
|
||||||
|
path: '/bunny/my/a/children',
|
||||||
|
component: () => import('@/views/bunny/my/a/aChildren.vue'),
|
||||||
|
},
|
||||||
{ name: 'bunny_my_a_b', path: '/bunny/my/a/b', component: () => import('@/views/bunny/my/a/b/index.vue') },
|
{ name: 'bunny_my_a_b', path: '/bunny/my/a/b', component: () => import('@/views/bunny/my/a/b/index.vue') },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
export default {
|
|
||||||
name: 'sw',
|
|
||||||
path: '/sw',
|
|
||||||
};
|
|
|
@ -3,11 +3,13 @@ import { resolve } from 'path';
|
||||||
import { defineConfig, UserConfig } from 'vite';
|
import { defineConfig, UserConfig } from 'vite';
|
||||||
import legacy from '@vitejs/plugin-legacy';
|
import legacy from '@vitejs/plugin-legacy';
|
||||||
import vueJsx from '@vitejs/plugin-vue2-jsx';
|
import vueJsx from '@vitejs/plugin-vue2-jsx';
|
||||||
|
import { compression } from 'vite-plugin-compression2';
|
||||||
|
|
||||||
export default defineConfig(
|
export default defineConfig(
|
||||||
(): UserConfig => ({
|
(): UserConfig => ({
|
||||||
// base: 'www.example.com',// ? 在每个文件前加上这个前缀
|
// base: './', // ? 在每个文件前加上这个前缀
|
||||||
// publicDir: './static',// ? 设置静态资源目录
|
// publicDir: './static',// ? 设置静态资源目录
|
||||||
|
envPrefix: 'BUNNY',
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve(__dirname, './src'),
|
'@': resolve(__dirname, './src'),
|
||||||
|
@ -21,18 +23,18 @@ export default defineConfig(
|
||||||
cors: true,
|
cors: true,
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': {
|
'/api': {
|
||||||
target: process.env.VUE_APP_URL,
|
target: process.env.BUNNY_APP_URL,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path: string) => path.replace(/^\/api/, '/api'),
|
rewrite: (path: string) => path.replace(/^\/api/, '/api'),
|
||||||
},
|
},
|
||||||
'/mock': {
|
'/mock': {
|
||||||
target: process.env.VUE_APP_URL,
|
target: process.env.BUNNY_APP_URL,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path: string) => path.replace(/^\/mock/, ''),
|
rewrite: (path: string) => path.replace(/^\/mock/, '/mock'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [vue(), legacy({ targets: ['defaults', 'not IE 11'] }), vueJsx()],
|
plugins: [vue(), legacy({ targets: ['defaults', 'not IE 11'] }), vueJsx(), compression()],
|
||||||
esbuild: {
|
esbuild: {
|
||||||
pure: ['console.log', 'debugger'],
|
pure: ['console.log', 'debugger'],
|
||||||
jsxFactory: 'h',
|
jsxFactory: 'h',
|
||||||
|
@ -71,9 +73,16 @@ export default defineConfig(
|
||||||
// 用于配置输出选项
|
// 用于配置输出选项
|
||||||
output: {
|
output: {
|
||||||
// 静态资源分类和包装
|
// 静态资源分类和包装
|
||||||
chunkFileNames: 'assets/js/[name]-[hash].js', // 用于指定代码分块的输出文件名格式
|
chunkFileNames: 'js/[name]-[hash].js', // 用于指定代码分块的输出文件名格式
|
||||||
entryFileNames: 'assets/js/[name]-[hash].js', // 用于指定入口文件的输出文件名格式
|
entryFileNames: 'js/[name]-[hash].js', // 用于指定入口文件的输出文件名格式
|
||||||
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]', // 用于指定静态资源的输出文件名格式
|
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]', // 用于指定静态资源的输出文件名格式
|
||||||
|
// ? 配置文件生成方式
|
||||||
|
manualChunks: (id, meta) => {
|
||||||
|
// 如果是包含在包中则打包成 vendor
|
||||||
|
if (id.includes('mode_modules')) {
|
||||||
|
return 'vendor';
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue