Commit 9b9fe71d authored by Step_by_step's avatar Step_by_step

feat: 支持按需打包

parent 10f2c2c8
...@@ -4,6 +4,8 @@ npm run build 打包 ...@@ -4,6 +4,8 @@ npm run build 打包
npm run dev 本地运行 npm run dev 本地运行
npm run preview 本地预览打包完的文件
### 如何添加模块 ### 如何添加模块
添加一个子应用至 modules ,子应用首页如下设置说明模块名 添加一个子应用至 modules ,子应用首页如下设置说明模块名
......
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head>
<meta charset="UTF-8"> <head>
<link rel="icon" href="/favicon.ico"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="icon" href="/favicon.ico">
<title>Vite App</title> <meta name="x5-cache" content="disable" />
</head> <meta name="x5-fullscreen" content="true" />
<body> <meta name="full-screen" content="yes" />
<div id="app"></div> <meta content="no-cache, no-store, must-revalidate" http-equiv="Cache-Control" />
<script type="module" src="/src/main.js"></script> <meta content="no-cache" http-equiv="Pragma" />
</body> <meta content="0" http-equiv="Expires" />
</html> <meta http-equiv="expires" content="0" />
<meta name="viewport"
content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,viewport-fit=cover">
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
\ No newline at end of file
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
"name": "komatsu-lease-app", "name": "komatsu-lease-app",
"version": "0.1.0", "version": "0.1.0",
"scripts": { "scripts": {
"dev": "VITE_TARGET=ALL vite ", "dev": "vite ",
"build": "vite build", "build": "vite build",
"preview": "vite preview",
"build:selfService": "VITE_TARGET=selfService vite build", "build:selfService": "VITE_TARGET=selfService vite build",
"build:intention": "VITE_TARGET=intention vite build", "build:intention": "VITE_TARGET=intention vite build",
"build:calculator": "VITE_TARGET=calculator vite build" "build:calculator": "VITE_TARGET=calculator vite build"
......
...@@ -32,10 +32,14 @@ export default { ...@@ -32,10 +32,14 @@ export default {
async mounted() { async mounted() {
const TempAccess = import.meta.env.DEV ? '60243b9f-5f2b-41f8-8007-67984b5ae1cd' : '' const TempAccess = import.meta.env.DEV ? '60243b9f-5f2b-41f8-8007-67984b5ae1cd' : ''
const jumpRouter = await login(TempAccess) if (import.meta.env.PROD) {
let index = this.$router.getRoutes().filter(route => route.meta.title)
this.$router.push({ path: index[0].path, replace: true });
return;
}
const route = this.$router; const jumpRouter = await login(TempAccess)
route.replace(jumpRouter.path ? jumpRouter : "applications"); this.$router.push({ path: jumpRouter.path ? jumpRouter : "applications", replace: true });
} }
}; };
</script> </script>
......
...@@ -4,14 +4,13 @@ import App from './App.vue' ...@@ -4,14 +4,13 @@ import App from './App.vue'
import router from './router' import router from './router'
import moment from 'moment' import moment from 'moment'
import { Notify, Toast } from 'vant'; import { Notify, Toast } from 'vant';
import VConsole from 'vconsole'
moment.locale('zh-cn') moment.locale('zh-cn')
let vConsole // if (import.meta.env.VITE_DEBUG === "true") {
if (import.meta.env.VITE_DEBUG === "true") { const vConsole = new VConsole();
let vc = await import("vconsole"); // }
vConsole = new vc.default();
}
const app = createApp(App) const app = createApp(App)
......
...@@ -5,7 +5,7 @@ let realRoutes = routes; ...@@ -5,7 +5,7 @@ let realRoutes = routes;
if (import.meta.env.PROD) { if (import.meta.env.PROD) {
let reg = new RegExp(`${import.meta.env.VITE_TARGET}`); let reg = new RegExp(`${import.meta.env.VITE_TARGET}`);
realRoutes = realRoutes.filter((route) => reg.test(route.path)) realRoutes = realRoutes.filter((route) => reg.test(route.name))
} }
console.info('已渲染路由--', realRoutes); console.info('已渲染路由--', realRoutes);
......
import { fileURLToPath, URL } from 'node:url' import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite' import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy' import legacy from '@vitejs/plugin-legacy'
import Pages from 'vite-plugin-pages' import Pages from 'vite-plugin-pages'
...@@ -25,39 +25,55 @@ const loader_pxtovw = pxtovw({ ...@@ -25,39 +25,55 @@ const loader_pxtovw = pxtovw({
landscapeWidth: 568 landscapeWidth: 568
}) })
const setRouteConfig = (VITE_TARGET) => {
let dirs = ['src/views', 'src/modules']
if (VITE_TARGET) {
dirs = [{ dir: `src/modules/${VITE_TARGET}`, baseRoute: VITE_TARGET }]
}
return {
dirs,
extensions: ['vue'],
exclude: ['**/components/*.vue']
}
}
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default { export default ({ mode }) => {
plugins: [ let VITE_TARGET = loadEnv(mode, process.cwd()).VITE_TARGET;
vue({ reactivityTransform: true }), return {
Pages({ plugins: [
dirs: ['src/views', 'src/modules'], vue({ reactivityTransform: true }),
extensions: ['vue'], Pages(setRouteConfig(VITE_TARGET)),
exclude: ['**/components/*.vue'] legacy({
}), targets: ['defaults', 'not IE 11']
legacy({ }),
targets: ['defaults', 'not IE 11'] styleImport({
}), resolves: [VantResolve()],
styleImport({ libs: [{
resolves: [VantResolve()], libraryName: 'vant',
libs: [{ esModule: false,
libraryName: 'vant', resolveStyle: (name) => `vant/es/${name}/style/index`
esModule: false, }],
resolveStyle: (name) => `vant/es/${name}/style/index` }),
}], ],
}), css: {
], postcss: {
css: { plugins: [loader_pxtovw]
postcss: { }
plugins: [loader_pxtovw] },
} resolve: {
}, alias: {
resolve: { '@': fileURLToPath(new URL('./src', import.meta.url))
alias: { }
'@': fileURLToPath(new URL('./src', import.meta.url)) },
server: {
host: '0.0.0.0',
port: 5678
},
build: {
outDir: `dist/${VITE_TARGET}`
} }
},
server: {
host: '0.0.0.0',
port: 5678
} }
} }
File deleted
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment