Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rspack/webpack/vite菜单修复 #158

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const config = {
},
define: {
'process.env': {},
BUILD_TOOLS: "'VITE'"
},
css: {
preprocessorOptions: {
Expand Down
1 change: 1 addition & 0 deletions packages/toolkits/pro/template/tinyvue/rspack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const config = {
'import.meta.env.VITE_USE_MOCK': 'false',
'import.meta.env.VITE_MOCK_IGNORE': '"/api/user/userInfo,/api/user/login,/api/user/register,/api/employee/getEmployee"',
'import.meta.env.VITE_MOCK_SERVER_HOST': '"/mock"',
BUILD_TOOLS: "'RSPACK'",
})
],
devServer: {
Expand Down
14 changes: 12 additions & 2 deletions packages/toolkits/pro/template/tinyvue/src/router/guard/menu.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import { useMenuStore } from "@/store/modules/router";
import { nextTick } from "vue";
import { Router, RouteRecordRaw } from "vue-router";
Expand Down Expand Up @@ -25,8 +26,17 @@ export interface ITreeNodeData {
locale: string;
}
const reg = /\.vue$/gim;
const views = import.meta.glob ? import.meta.glob('../../views/**/*.vue') : require.context('../../views', true, reg, 'sync');
console.log(views)
let views = {} as any;
if(BUILD_TOOLS === 'VITE' || BUILD_TOOLS === 'WEBPACK'){
views = import.meta.glob('../../views/**/*.vue')
}else if(BUILD_TOOLS === 'RSPACK'){
const components = require.context('../../views', true, reg, 'sync');
components.keys().forEach((path) => {
if(path.endsWith('.vue')){
views[`../../views/${path.replace('./','')}`] = ()=>components(path);
}
})
}
const toRoutes = (menus: ITreeNodeData[]) => {
const router: RouteRecordRaw[] = [];
for (let i=0;i<menus.length;i+=1) {
Expand Down
1 change: 1 addition & 0 deletions packages/toolkits/pro/template/tinyvue/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ module.exports = {
'import.meta.env.VITE_USE_MOCK': 'false',
'import.meta.env.VITE_MOCK_IGNORE': '"/api/user/userInfo,/api/user/login,/api/user/register,/api/employee/getEmployee"',
'import.meta.env.VITE_MOCK_SERVER_HOST': '"/mock"',
BUILD_TOOLS: "'WEBPACK'",
})
],
resolve: {
Expand Down