mirror of
https://gitee.com/WeBank/fes.js.git
synced 2024-11-30 10:48:12 +08:00
Merge pull request #83 from WeBankFinTech/router-jsx
feat: 路由生成支持 .jsx 后缀
This commit is contained in:
commit
9be4ebe415
@ -4,8 +4,11 @@ import {
|
||||
} from 'path';
|
||||
import { lodash } from '@fesjs/utils';
|
||||
import { parse } from '@vue/compiler-sfc';
|
||||
import { Logger } from '@fesjs/compiler';
|
||||
import { runtimePath } from '../../../utils/constants';
|
||||
|
||||
const logger = new Logger('fes:router');
|
||||
|
||||
// pages
|
||||
// ├── index.vue # 根路由页面 路径 /
|
||||
// ├── *.vue # 模糊匹配 路径 *
|
||||
@ -18,7 +21,7 @@ import { runtimePath } from '../../../utils/constants';
|
||||
|
||||
const isProcessFile = function (path) {
|
||||
const ext = extname(path);
|
||||
return statSync(path).isFile() && ['.vue'].includes(ext);
|
||||
return statSync(path).isFile() && ['.vue', '.jsx'].includes(ext);
|
||||
};
|
||||
|
||||
const isProcessDirectory = function (path, item) {
|
||||
@ -68,6 +71,8 @@ const getRoutePath = function (parentRoutePath, fileName) {
|
||||
return posix.join(parentRoutePath, fileName);
|
||||
};
|
||||
|
||||
let cacheGenRoutes = {};
|
||||
|
||||
// TODO 约定 layout 目录作为布局文件夹,
|
||||
const genRoutes = function (parentRoutes, path, parentRoutePath, config) {
|
||||
const dirList = readdirSync(path);
|
||||
@ -91,6 +96,12 @@ const genRoutes = function (parentRoutes, path, parentRoutePath, config) {
|
||||
const fileName = basename(item, ext);
|
||||
// 路由的path
|
||||
const routePath = getRoutePath(parentRoutePath, fileName);
|
||||
if (cacheGenRoutes[routePath]) {
|
||||
logger.warn(`[WARNING]: The file path: ${routePath}(.jsx/.vue) conflict in router,will only use ${routePath}.jsx,please remove one of.`);
|
||||
return;
|
||||
}
|
||||
cacheGenRoutes[routePath] = true;
|
||||
|
||||
// 路由名称
|
||||
const routeName = getRouteName(parentRoutePath, fileName);
|
||||
const componentPath = getComponentPath(parentRoutePath, fileName, config);
|
||||
@ -172,6 +183,7 @@ const getRoutes = function ({ config, absPagesPath }) {
|
||||
if (configRoutes && configRoutes.length > 0) return configRoutes;
|
||||
|
||||
const routes = [];
|
||||
cacheGenRoutes = {};
|
||||
genRoutes(routes, absPagesPath, '/', config);
|
||||
rank(routes);
|
||||
return routes;
|
||||
|
7
packages/fes-template-h5/src/pages/abc/test.jsx
Normal file
7
packages/fes-template-h5/src/pages/abc/test.jsx
Normal file
@ -0,0 +1,7 @@
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
return () => <div>hello jsx</div>;
|
||||
}
|
||||
});
|
3
packages/fes-template-h5/src/pages/abc/test.vue
Normal file
3
packages/fes-template-h5/src/pages/abc/test.vue
Normal file
@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<div>hello vue</div>
|
||||
</template>
|
7
packages/fes-template-h5/src/pages/test.jsx
Normal file
7
packages/fes-template-h5/src/pages/test.jsx
Normal file
@ -0,0 +1,7 @@
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
return () => <div>hello jsx</div>;
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user