Commit 9b9fe71d authored by Step_by_step's avatar Step_by_step

feat: 支持按需打包

parent 10f2c2c8
......@@ -4,6 +4,8 @@ npm run build 打包
npm run dev 本地运行
npm run preview 本地预览打包完的文件
### 如何添加模块
添加一个子应用至 modules ,子应用首页如下设置说明模块名
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="x5-cache" content="disable" />
<meta name="x5-fullscreen" content="true" />
<meta name="full-screen" content="yes" />
<meta content="no-cache, no-store, must-revalidate" http-equiv="Cache-Control" />
<meta content="no-cache" http-equiv="Pragma" />
<meta content="0" http-equiv="Expires" />
<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 @@
"name": "komatsu-lease-app",
"version": "0.1.0",
"scripts": {
"dev": "VITE_TARGET=ALL vite ",
"dev": "vite ",
"build": "vite build",
"preview": "vite preview",
"build:selfService": "VITE_TARGET=selfService vite build",
"build:intention": "VITE_TARGET=intention vite build",
"build:calculator": "VITE_TARGET=calculator vite build"
......
......@@ -32,10 +32,14 @@ export default {
async mounted() {
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;
route.replace(jumpRouter.path ? jumpRouter : "applications");
const jumpRouter = await login(TempAccess)
this.$router.push({ path: jumpRouter.path ? jumpRouter : "applications", replace: true });
}
};
</script>
......
......@@ -4,14 +4,13 @@ import App from './App.vue'
import router from './router'
import moment from 'moment'
import { Notify, Toast } from 'vant';
import VConsole from 'vconsole'
moment.locale('zh-cn')
let vConsole
if (import.meta.env.VITE_DEBUG === "true") {
let vc = await import("vconsole");
vConsole = new vc.default();
}
// if (import.meta.env.VITE_DEBUG === "true") {
const vConsole = new VConsole();
// }
const app = createApp(App)
......
......@@ -5,7 +5,7 @@ let realRoutes = routes;
if (import.meta.env.PROD) {
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);
......
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
import Pages from 'vite-plugin-pages'
......@@ -25,39 +25,55 @@ const loader_pxtovw = pxtovw({
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/
export default {
plugins: [
vue({ reactivityTransform: true }),
Pages({
dirs: ['src/views', 'src/modules'],
extensions: ['vue'],
exclude: ['**/components/*.vue']
}),
legacy({
targets: ['defaults', 'not IE 11']
}),
styleImport({
resolves: [VantResolve()],
libs: [{
libraryName: 'vant',
esModule: false,
resolveStyle: (name) => `vant/es/${name}/style/index`
}],
}),
],
css: {
postcss: {
plugins: [loader_pxtovw]
}
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
export default ({ mode }) => {
let VITE_TARGET = loadEnv(mode, process.cwd()).VITE_TARGET;
return {
plugins: [
vue({ reactivityTransform: true }),
Pages(setRouteConfig(VITE_TARGET)),
legacy({
targets: ['defaults', 'not IE 11']
}),
styleImport({
resolves: [VantResolve()],
libs: [{
libraryName: 'vant',
esModule: false,
resolveStyle: (name) => `vant/es/${name}/style/index`
}],
}),
],
css: {
postcss: {
plugins: [loader_pxtovw]
}
},
resolve: {
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