routes.js
1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.routeToChunkName = void 0;
function _react() {
const data = _interopRequireDefault(require("react"));
_react = function _react() {
return data;
};
return data;
}
function _lodash() {
const data = require("@umijs/deps/compiled/lodash");
_lodash = function _lodash() {
return data;
};
return data;
}
var _winPath = _interopRequireDefault(require("./winPath/winPath"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function lastSlash(str) {
return str[str.length - 1] === '/' ? str : `${str}/`;
}
/**
* transform route component into webpack chunkName
* @param param0
*/
const routeToChunkName = ({
route,
cwd
} = {
route: {}
}) => {
return typeof route.component === 'string' ? route.component.replace(new RegExp(`^${(0, _lodash().escapeRegExp)(lastSlash((0, _winPath.default)(cwd || '/')))}`), '').replace(/^.(\/|\\)/, '').replace(/(\/|\\)/g, '__').replace(/\.jsx?$/, '').replace(/\.tsx?$/, '').replace(/^src__/, '').replace(/\.\.__/g, '') // 约定式路由的 [ 会导致 webpack 的 code splitting 失败
// ref: https://github.com/umijs/umi/issues/4155
.replace(/[\[\]]/g, '') // 插件层的文件也可能是路由组件,比如 plugin-layout 插件
.replace(/^.umi-production__/, 't__').replace(/^pages__/, 'p__').replace(/^page__/, 'p__') : '';
};
exports.routeToChunkName = routeToChunkName;