swico 1.7.3 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/package.json +7 -13
  2. package/src/bin.js +6 -6
  3. package/src/command/build.js +33 -73
  4. package/src/command/start.js +99 -191
  5. package/src/config/rsbpack.dev.js +104 -0
  6. package/src/config/{webpack.base.react.d.ts → rspack.base.react.d.ts} +13 -3
  7. package/src/config/rspack.base.react.js +193 -0
  8. package/src/config/{webpack.base.vue.d.ts → rspack.base.vue.d.ts} +13 -1
  9. package/src/config/rspack.base.vue.js +282 -0
  10. package/src/config/rspack.prod.js +123 -0
  11. package/src/index.js +3 -5
  12. package/src/index.react.js +5 -10
  13. package/src/index.vue.js +4 -6
  14. package/src/project-path/.swico-react/$env/history.js +65 -66
  15. package/src/project-path/.swico-react/$env/index.js +29 -47
  16. package/src/project-path/.swico-react/loading.js +1 -1
  17. package/src/project-path/.swico-react/react-hooks.js +24 -37
  18. package/src/project-path/.swico-vue/$env/history.js +25 -36
  19. package/src/project-path/.swico-vue/$env/index.js +7 -7
  20. package/src/project-path/.swico-vue/Container.js +1 -1
  21. package/src/project-path/.swico-vue/vue-hooks.js +17 -28
  22. package/src/project-path/src/layout/Layout.js +1 -1
  23. package/src/project-path/src/layout/index.js +3 -3
  24. package/src/task.js +13 -58
  25. package/src/utils/config.js +185 -349
  26. package/src/utils/tools.js +103 -199
  27. package/src/config/webpack.base.react.js +0 -315
  28. package/src/config/webpack.base.vue.js +0 -338
  29. package/src/config/webpack.dev.js +0 -159
  30. package/src/config/webpack.prod.js +0 -193
  31. /package/src/config/{webpack.dev.d.ts → rsbpack.dev.d.ts} +0 -0
  32. /package/src/config/{webpack.prod.d.ts → rspack.prod.d.ts} +0 -0
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const webpack_bundle_analyzer_1 = __importDefault(require("webpack-bundle-analyzer"));
39
+ const path_1 = __importDefault(require("path"));
40
+ const fs_extra_1 = __importDefault(require("fs-extra"));
41
+ const config_1 = require("../utils/config");
42
+ const webpack_merge_1 = require("webpack-merge");
43
+ const webpackbar_1 = __importDefault(require("webpackbar"));
44
+ const tools_1 = require("../utils/tools");
45
+ const core_1 = require("@rspack/core");
46
+ const BundleAnalyzerPlugin = webpack_bundle_analyzer_1.default.BundleAnalyzerPlugin;
47
+ const isAnalyze = process.env.ANALYZE === 'true';
48
+ function default_1(options) {
49
+ var _a, _b, _c, _d, _e, _f, _g;
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const { projectPath, customConfig, templateType } = options;
52
+ const getBaseConfig = (yield Promise.resolve(`${templateType === 'vue' ? './webpack.base.vue' : './webpack.base.react'}`).then(s => __importStar(require(s)))).default;
53
+ const baseConfig = yield getBaseConfig(Object.assign(Object.assign({}, options), { env: 'prod' }));
54
+ const consoleAvailable = (_b = (_a = customConfig.prod) === null || _a === void 0 ? void 0 : _a.console) !== null && _b !== void 0 ? _b : config_1.initConfig.console;
55
+ const isPublicDirExist = yield fs_extra_1.default.exists(path_1.default.join(projectPath, '/public'));
56
+ const copyConfig = (_d = (_c = customConfig.prod) === null || _c === void 0 ? void 0 : _c.copy) !== null && _d !== void 0 ? _d : config_1.initConfig.copy;
57
+ const customDevtool = (_e = customConfig.prod.devtool) !== null && _e !== void 0 ? _e : customConfig.base.devtool;
58
+ return (0, webpack_merge_1.merge)(baseConfig, {
59
+ performance: {
60
+ hints: false
61
+ },
62
+ mode: 'production',
63
+ devtool: customDevtool !== null && customDevtool !== void 0 ? customDevtool : undefined,
64
+ optimization: {
65
+ runtimeChunk: true,
66
+ minimize: true,
67
+ splitChunks: {
68
+ chunks: 'all',
69
+ cacheGroups: {
70
+ vendors: {
71
+ test: /[\\/]node_modules[\\/]/,
72
+ priority: -10,
73
+ chunks: 'all',
74
+ reuseExistingChunk: true
75
+ },
76
+ commons: {
77
+ minSize: 0,
78
+ minChunks: 2,
79
+ priority: -20,
80
+ chunks: 'all',
81
+ reuseExistingChunk: true
82
+ }
83
+ }
84
+ }
85
+ },
86
+ plugins: [
87
+ ...(isPublicDirExist || copyConfig.length > 0
88
+ ? [
89
+ new core_1.rspack.CopyRspackPlugin({
90
+ patterns: [
91
+ ...(isPublicDirExist ? [path_1.default.join(projectPath, '/public')] : []),
92
+ ...copyConfig
93
+ ]
94
+ })
95
+ ]
96
+ : []),
97
+ ...(isAnalyze
98
+ ? [
99
+ new BundleAnalyzerPlugin({
100
+ analyzerMode: 'server',
101
+ analyzerHost: '127.0.0.1',
102
+ analyzerPort: 'auto',
103
+ reportFilename: 'report.html',
104
+ defaultSizes: 'stat',
105
+ openAnalyzer: true,
106
+ generateStatsFile: false,
107
+ statsFilename: 'analyze.json',
108
+ statsOptions: null,
109
+ logLevel: 'info'
110
+ })
111
+ ]
112
+ : []),
113
+ new webpackbar_1.default({
114
+ name: 'Swico',
115
+ color: tools_1.colorConfig.theme,
116
+ profile: false
117
+ }),
118
+ ...((_g = (_f = customConfig.prod) === null || _f === void 0 ? void 0 : _f.plugins) !== null && _g !== void 0 ? _g : [])
119
+ ]
120
+ });
121
+ });
122
+ }
123
+ exports.default = default_1;
package/src/index.js CHANGED
@@ -3,10 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defineGlobal = exports.defineConfig = exports.useNav = exports.useLocation = exports.Link = exports.Outlet = exports.history = void 0;
4
4
  var mock_history_1 = require("./mock-history");
5
5
  Object.defineProperty(exports, "history", { enumerable: true, get: function () { return mock_history_1.history; } });
6
- var Outlet, Link, useLocation, useNav;
7
- var defineConfig = function (env, config) { return config; };
6
+ let Outlet, Link, useLocation, useNav;
7
+ const defineConfig = (env, config) => config;
8
8
  exports.defineConfig = defineConfig;
9
- var defineGlobal = function (config) {
10
- return config;
11
- };
9
+ const defineGlobal = (config) => config;
12
10
  exports.defineGlobal = defineGlobal;
@@ -4,12 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.defineGlobal = exports.defineConfig = exports.history = exports.useNav = exports.useLocation = exports.Outlet = exports.Link = void 0;
7
- var react_router_dom_1 = require("react-router-dom");
8
- var react_1 = __importDefault(require("react"));
9
- var Link = function (_a) {
10
- var replace = _a.replace, to = _a.to, style = _a.style, className = _a.className, children = _a.children;
11
- return react_1.default.createElement(react_router_dom_1.Link, { replace: replace, to: to, style: style, className: className }, children);
12
- };
7
+ const react_router_dom_1 = require("react-router-dom");
8
+ const react_1 = __importDefault(require("react"));
9
+ const Link = ({ replace, to, style, className, children }) => react_1.default.createElement(react_router_dom_1.Link, { replace, to, style, className }, children);
13
10
  exports.Link = Link;
14
11
  var react_router_dom_2 = require("react-router-dom");
15
12
  Object.defineProperty(exports, "Outlet", { enumerable: true, get: function () { return react_router_dom_2.Outlet; } });
@@ -18,9 +15,7 @@ Object.defineProperty(exports, "useLocation", { enumerable: true, get: function
18
15
  Object.defineProperty(exports, "useNav", { enumerable: true, get: function () { return react_hooks_1.useNav; } });
19
16
  var mock_history_1 = require("./mock-history");
20
17
  Object.defineProperty(exports, "history", { enumerable: true, get: function () { return mock_history_1.history; } });
21
- var defineConfig = function (env, config) { return config; };
18
+ const defineConfig = (env, config) => config;
22
19
  exports.defineConfig = defineConfig;
23
- var defineGlobal = function (config) {
24
- return config;
25
- };
20
+ const defineGlobal = (config) => config;
26
21
  exports.defineGlobal = defineGlobal;
package/src/index.vue.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defineGlobal = exports.defineConfig = exports.Link = exports.history = exports.useNav = exports.useLocation = exports.Outlet = void 0;
4
- var vue_1 = require("vue");
5
- var vue_router_1 = require("vue-router");
4
+ const vue_1 = require("vue");
5
+ const vue_router_1 = require("vue-router");
6
6
  var vue_router_2 = require("vue-router");
7
7
  Object.defineProperty(exports, "Outlet", { enumerable: true, get: function () { return vue_router_2.RouterView; } });
8
8
  var vue_hooks_1 = require("./project-path/.swico-vue/vue-hooks");
@@ -24,9 +24,7 @@ exports.Link = (0, vue_1.defineComponent)({
24
24
  },
25
25
  template: '<RouterLink :to="to" :replace="replace" ><slot></slot></RouterLink>'
26
26
  });
27
- var defineConfig = function (env, config) { return config; };
27
+ const defineConfig = (env, config) => config;
28
28
  exports.defineConfig = defineConfig;
29
- var defineGlobal = function (config) {
30
- return config;
31
- };
29
+ const defineGlobal = (config) => config;
32
30
  exports.defineGlobal = defineGlobal;
@@ -4,20 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.history = exports.getHistory = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns = void 0;
7
- var qs_1 = __importDefault(require("qs"));
8
- var routes_1 = __importDefault(require("./routes"));
9
- var config_1 = require("./config");
10
- var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
11
- var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
12
- var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
13
- var patternWithValuesParts = urlPatternWithValues.split('/');
14
- var patternWithParamsParts = urlPatternWithParams.split('/');
7
+ const qs_1 = __importDefault(require("qs"));
8
+ const routes_1 = __importDefault(require("./routes"));
9
+ const config_1 = require("./config");
10
+ const lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
11
+ const formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
12
+ const compareURLPatterns = (urlPatternWithValues, urlPatternWithParams) => {
13
+ const patternWithValuesParts = urlPatternWithValues.split('/');
14
+ const patternWithParamsParts = urlPatternWithParams.split('/');
15
15
  if (patternWithValuesParts.length !== patternWithParamsParts.length) {
16
16
  return false;
17
17
  }
18
- for (var i = 0; i < patternWithValuesParts.length; i++) {
19
- var valuePart = patternWithValuesParts[i];
20
- var paramPart = patternWithParamsParts[i];
18
+ for (let i = 0; i < patternWithValuesParts.length; i++) {
19
+ const valuePart = patternWithValuesParts[i];
20
+ const paramPart = patternWithParamsParts[i];
21
21
  if (paramPart.startsWith(':') && paramPart !== '') {
22
22
  continue;
23
23
  }
@@ -28,17 +28,17 @@ var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
28
28
  return true;
29
29
  };
30
30
  exports.compareURLPatterns = compareURLPatterns;
31
- var interpolatePath = function (pathTemplate, params) {
32
- var pathParts = pathTemplate.split('/');
33
- var interpolatedParts = pathParts.map(function (part) {
34
- var paramMatch = part.match(/^\:(.+)$/);
31
+ const interpolatePath = (pathTemplate, params) => {
32
+ const pathParts = pathTemplate.split('/');
33
+ const interpolatedParts = pathParts.map((part) => {
34
+ const paramMatch = part.match(/^\:(.+)$/);
35
35
  if (paramMatch) {
36
- var paramName = paramMatch[1];
36
+ const paramName = paramMatch[1];
37
37
  if (params[paramName]) {
38
38
  return params[paramName];
39
39
  }
40
40
  else {
41
- throw "Missing required params '".concat(paramName, "'");
41
+ throw `Missing required params '${paramName}'`;
42
42
  }
43
43
  }
44
44
  return part;
@@ -46,118 +46,117 @@ var interpolatePath = function (pathTemplate, params) {
46
46
  return interpolatedParts.join('/');
47
47
  };
48
48
  exports.interpolatePath = interpolatePath;
49
- var interpolatePathParams = function (pathTemplate, path) {
49
+ const interpolatePathParams = (pathTemplate = '', path) => {
50
50
  var _a;
51
- if (pathTemplate === void 0) { pathTemplate = ''; }
52
- var regexPattern = pathTemplate.replace(/:(\w+)/g, '([^/]+)');
53
- var regex = new RegExp("^".concat(regexPattern, "$"));
54
- var match = path.match(regex);
51
+ const regexPattern = pathTemplate.replace(/:(\w+)/g, '([^/]+)');
52
+ const regex = new RegExp(`^${regexPattern}$`);
53
+ const match = path.match(regex);
55
54
  if (match) {
56
- var params_1 = match.slice(1);
57
- var paramNames = ((_a = pathTemplate.match(/:(\w+)/g)) === null || _a === void 0 ? void 0 : _a.map(function (name) { return name.slice(1); })) || [];
58
- var result_1 = {};
59
- paramNames.forEach(function (name, index) {
60
- result_1[name] = params_1[index];
55
+ const params = match.slice(1);
56
+ const paramNames = ((_a = pathTemplate.match(/:(\w+)/g)) === null || _a === void 0 ? void 0 : _a.map((name) => name.slice(1))) || [];
57
+ const result = {};
58
+ paramNames.forEach((name, index) => {
59
+ result[name] = params[index];
61
60
  });
62
- return result_1;
61
+ return result;
63
62
  }
64
63
  return {};
65
64
  };
66
- var formatAncPath = function (ancPath) {
67
- var newAncPath = ancPath.startsWith('/') ? ancPath : '/' + ancPath;
65
+ const formatAncPath = (ancPath) => {
66
+ let newAncPath = ancPath.startsWith('/') ? ancPath : '/' + ancPath;
68
67
  newAncPath = newAncPath.endsWith('/') ? newAncPath.slice(0, -1) : newAncPath;
69
68
  return newAncPath;
70
69
  };
71
70
  exports.formatAncPath = formatAncPath;
72
- var getPathNameList = function (routes) {
73
- var list = [];
74
- var checkRouteItem = function (item, ancPath) {
75
- var path = item.path, name = item.name, children = item.children, custom = item.custom;
76
- var newAncPath = "".concat((0, exports.formatAncPath)(ancPath)).concat(path.startsWith('/') ? path : '/' + path);
77
- list.push({ path: newAncPath, name: name, custom: custom });
71
+ const getPathNameList = (routes) => {
72
+ const list = [];
73
+ const checkRouteItem = (item, ancPath) => {
74
+ const { path, name, children, custom } = item;
75
+ const newAncPath = `${(0, exports.formatAncPath)(ancPath)}${path.startsWith('/') ? path : '/' + path}`;
76
+ list.push({ path: newAncPath, name, custom });
78
77
  if (children) {
79
- children.some(function (item) { return checkRouteItem(item, newAncPath); });
78
+ children.some((item) => checkRouteItem(item, newAncPath));
80
79
  }
81
80
  };
82
- routes.forEach(function (item) { return checkRouteItem(item, ''); });
81
+ routes.forEach((item) => checkRouteItem(item, ''));
83
82
  return list;
84
83
  };
85
84
  exports.pathNameList = getPathNameList(routes_1.default);
86
- var getLocation = function (historyLocation) {
87
- var pathname = historyLocation.pathname, hash = historyLocation.hash, search = historyLocation.search, state = historyLocation.state;
88
- var routerBaseLength = formatRouterBase.length;
89
- var path = pathname.slice(routerBaseLength);
90
- var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || (0, exports.compareURLPatterns)(path, item.path); });
91
- var params = interpolatePathParams(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
85
+ const getLocation = (historyLocation) => {
86
+ const { pathname, hash, search, state } = historyLocation;
87
+ const routerBaseLength = formatRouterBase.length;
88
+ const path = pathname.slice(routerBaseLength);
89
+ const matchPathNameItem = exports.pathNameList.find((item) => item.path === path || (0, exports.compareURLPatterns)(path, item.path));
90
+ const params = interpolatePathParams(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
92
91
  return {
93
92
  state: state !== null && state !== void 0 ? state : {},
94
- hash: hash,
95
- search: search,
96
- pathname: pathname,
93
+ hash,
94
+ search,
95
+ pathname,
97
96
  query: search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {},
98
97
  name: matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.name,
99
- params: params,
100
- path: path,
98
+ params,
99
+ path,
101
100
  custom: matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.custom
102
101
  };
103
102
  };
104
- var getFormatHistoryOption = function (to, pathList, type) {
103
+ const getFormatHistoryOption = (to, pathList, type) => {
105
104
  var _a;
106
- var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query;
107
- var obj = {
108
- hash: hash,
105
+ const { params, path, hash, name, query } = to;
106
+ let obj = {
107
+ hash,
109
108
  search: query ? qs_1.default.stringify(query) : undefined
110
109
  };
111
110
  if (path) {
112
111
  obj.pathname = path;
113
112
  }
114
113
  if (name) {
115
- var fullPath = (_a = pathList.find(function (item) { return item.name === name; })) === null || _a === void 0 ? void 0 : _a.path;
116
- var targetPath = fullPath ? (0, exports.interpolatePath)(fullPath, params) : null;
114
+ const fullPath = (_a = pathList.find((item) => item.name === name)) === null || _a === void 0 ? void 0 : _a.path;
115
+ const targetPath = fullPath ? (0, exports.interpolatePath)(fullPath, params) : null;
117
116
  if (targetPath) {
118
117
  obj.pathname = targetPath;
119
118
  }
120
119
  else {
121
- throw "An error occurred while executing 'history.".concat(type, "' operation: The path for the name \"").concat(name, "\" could not be found");
120
+ throw `An error occurred while executing 'history.${type}' operation: The path for the name "${name}" could not be found`;
122
121
  }
123
122
  }
124
123
  return obj;
125
124
  };
126
- var getHistory = function (router) {
125
+ const getHistory = (router) => {
127
126
  return {
128
- go: function (delta) {
127
+ go: (delta) => {
129
128
  router.navigate(delta);
130
129
  },
131
- forward: function () {
130
+ forward: () => {
132
131
  router.navigate(1);
133
132
  },
134
- back: function () {
133
+ back: () => {
135
134
  router.navigate(-1);
136
135
  },
137
- push: function (to) {
136
+ push: (to) => {
138
137
  switch (typeof to) {
139
138
  case 'string':
140
139
  router.navigate(to);
141
140
  break;
142
141
  case 'object':
143
- var formatOption = getFormatHistoryOption(to, exports.pathNameList, 'push');
142
+ const formatOption = getFormatHistoryOption(to, exports.pathNameList, 'push');
144
143
  router.navigate(formatOption, { state: to.state });
145
144
  break;
146
145
  default:
147
- throw "An error occurred while executing history.push operation: unexpected type of 'to':".concat(typeof to);
146
+ throw `An error occurred while executing history.push operation: unexpected type of 'to':${typeof to}`;
148
147
  }
149
148
  },
150
- replace: function (to) {
149
+ replace: (to) => {
151
150
  switch (typeof to) {
152
151
  case 'string':
153
152
  router.navigate(to, { replace: true });
154
153
  break;
155
154
  case 'object':
156
- var formatOption = getFormatHistoryOption(to, exports.pathNameList, 'replace');
155
+ const formatOption = getFormatHistoryOption(to, exports.pathNameList, 'replace');
157
156
  router.navigate(formatOption, { state: to.state, replace: true });
158
157
  break;
159
158
  default:
160
- throw "An error occurred while executing history.replace operation: unexpected type of 'to':".concat(typeof to);
159
+ throw `An error occurred while executing history.replace operation: unexpected type of 'to':${typeof to}`;
161
160
  }
162
161
  },
163
162
  get location() {
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
3
  if (k2 === undefined) k2 = k;
19
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -42,38 +27,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
42
27
  };
43
28
  Object.defineProperty(exports, "__esModule", { value: true });
44
29
  exports.getChildrenRouteList = void 0;
45
- var client_1 = require("react-dom/client");
46
- var react_1 = __importStar(require("react"));
47
- var react_router_dom_1 = require("react-router-dom");
48
- var loading_1 = __importDefault(require("../loading"));
49
- var history_1 = require("./history");
30
+ const client_1 = require("react-dom/client");
31
+ const react_1 = __importStar(require("react"));
32
+ const react_router_dom_1 = require("react-router-dom");
33
+ const loading_1 = __importDefault(require("../loading"));
34
+ const history_1 = require("./history");
50
35
  require("../../src/global");
51
- var layout_1 = __importDefault(require("../../src/layout"));
52
- var routes_1 = __importDefault(require("./routes"));
53
- var config_1 = require("./config");
54
- var Container = (function (_super) {
55
- __extends(Container, _super);
56
- function Container() {
57
- var _this = _super !== null && _super.apply(this, arguments) || this;
58
- _this.state = {
36
+ const layout_1 = __importDefault(require("../../src/layout"));
37
+ const routes_1 = __importDefault(require("./routes"));
38
+ const config_1 = require("./config");
39
+ class Container extends react_1.default.Component {
40
+ constructor() {
41
+ super(...arguments);
42
+ this.state = {
59
43
  error: null
60
44
  };
61
- return _this;
62
45
  }
63
- Container.getDerivedStateFromError = function (error) {
46
+ static getDerivedStateFromError(error) {
64
47
  return { error: error.toString() };
65
- };
66
- Container.prototype.componentDidCatch = function (error, errorInfo) {
67
- };
68
- Container.prototype.render = function () {
48
+ }
49
+ componentDidCatch(error, errorInfo) {
50
+ }
51
+ render() {
69
52
  return this.state.error ? null : this.props.children;
70
- };
71
- return Container;
72
- }(react_1.default.Component));
73
- var getChildrenRouteList = function (childrenRoutes, ancPathKey) {
74
- return childrenRoutes === null || childrenRoutes === void 0 ? void 0 : childrenRoutes.map(function (item) {
75
- var component = item.component, path = item.path, children = item.children, redirect = item.redirect;
76
- var newAncPathKey = "".concat(ancPathKey, "-").concat(path);
53
+ }
54
+ }
55
+ const getChildrenRouteList = (childrenRoutes, ancPathKey) => {
56
+ return childrenRoutes === null || childrenRoutes === void 0 ? void 0 : childrenRoutes.map((item) => {
57
+ const { component, path, children, redirect } = item;
58
+ const newAncPathKey = `${ancPathKey}-${path}`;
77
59
  return {
78
60
  element: redirect ? (react_1.default.createElement(react_router_dom_1.Navigate, { to: redirect, replace: true })) : component ? (react_1.default.createElement(react_1.Suspense, { fallback: react_1.default.createElement(loading_1.default, null) }, (0, react_1.createElement)((0, react_1.lazy)(component)))) : (react_1.default.createElement(react_router_dom_1.Outlet, null)),
79
61
  key: newAncPathKey,
@@ -83,8 +65,8 @@ var getChildrenRouteList = function (childrenRoutes, ancPathKey) {
83
65
  });
84
66
  };
85
67
  exports.getChildrenRouteList = getChildrenRouteList;
86
- var App = function () {
87
- var routeList = [
68
+ const App = () => {
69
+ const routeList = [
88
70
  {
89
71
  element: (react_1.default.createElement(Container, null,
90
72
  react_1.default.createElement(layout_1.default, null))),
@@ -92,18 +74,18 @@ var App = function () {
92
74
  children: (0, exports.getChildrenRouteList)(routes_1.default, '')
93
75
  }
94
76
  ];
95
- var router = (config_1.routerType === 'hash' ? react_router_dom_1.createHashRouter : react_router_dom_1.createBrowserRouter)(routeList, {
77
+ const router = (config_1.routerType === 'hash' ? react_router_dom_1.createHashRouter : react_router_dom_1.createBrowserRouter)(routeList, {
96
78
  basename: config_1.routerBase
97
79
  });
98
80
  if (config_1.routerBase && config_1.routerBase !== '/') {
99
81
  if (config_1.routerType === 'browser' && window.location.pathname === '/') {
100
- window.location.replace("".concat(config_1.routerBase));
82
+ window.location.replace(`${config_1.routerBase}`);
101
83
  }
102
84
  }
103
- (0, react_1.useLayoutEffect)(function () {
85
+ (0, react_1.useLayoutEffect)(() => {
104
86
  history_1.history = (0, history_1.getHistory)(router);
105
87
  });
106
88
  return react_1.default.createElement(react_router_dom_1.RouterProvider, { router: router });
107
89
  };
108
- var root = (0, client_1.createRoot)(document.getElementById('root'));
90
+ const root = (0, client_1.createRoot)(document.getElementById('root'));
109
91
  root.render(react_1.default.createElement(App, null));
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = (function () { return null; });
3
+ exports.default = () => null;
@@ -1,33 +1,20 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
5
  Object.defineProperty(exports, "__esModule", { value: true });
17
6
  exports.useNav = exports.useLocation = void 0;
18
- var react_router_dom_1 = require("react-router-dom");
19
- var history_1 = require("./$env/history");
20
- var qs_1 = __importDefault(require("qs"));
21
- var useLocation = function () {
7
+ const react_router_dom_1 = require("react-router-dom");
8
+ const history_1 = require("./$env/history");
9
+ const qs_1 = __importDefault(require("qs"));
10
+ const useLocation = () => {
22
11
  var _a;
23
- var location = (0, react_router_dom_1.useLocation)();
24
- var params = (0, react_router_dom_1.useParams)();
25
- var search = location.search, hash = location.hash, pathname = location.pathname, state = location.state;
26
- var matchItem = history_1.pathNameList.find(function (item) {
27
- return (Object.keys(params).length > 0 && (0, history_1.compareURLPatterns)(pathname, item.path)) ||
28
- item.path === pathname;
29
- });
30
- var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
12
+ const location = (0, react_router_dom_1.useLocation)();
13
+ const params = (0, react_router_dom_1.useParams)();
14
+ const { search, hash, pathname, state } = location;
15
+ const matchItem = history_1.pathNameList.find((item) => (Object.keys(params).length > 0 && (0, history_1.compareURLPatterns)(pathname, item.path)) ||
16
+ item.path === pathname);
17
+ const query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
31
18
  return {
32
19
  name: matchItem === null || matchItem === void 0 ? void 0 : matchItem.name,
33
20
  custom: matchItem === null || matchItem === void 0 ? void 0 : matchItem.custom,
@@ -35,25 +22,25 @@ var useLocation = function () {
35
22
  path: pathname,
36
23
  pathname: (_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.pathname,
37
24
  search: '',
38
- query: query,
39
- hash: hash,
40
- params: params
25
+ query,
26
+ hash,
27
+ params
41
28
  };
42
29
  };
43
30
  exports.useLocation = useLocation;
44
- var getFormatNavPath = function (to) {
31
+ const getFormatNavPath = (to) => {
45
32
  var _a;
46
- var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query;
47
- var search = query ? "?".concat(qs_1.default.stringify(query)) : '';
48
- var formatHash = hash ? (hash.startsWith('#') ? hash : "#".concat(hash)) : '';
49
- var formatPath = name ? (_a = history_1.pathNameList.find(function (item) { return item.name === name; })) === null || _a === void 0 ? void 0 : _a.path : path;
50
- var newPath = formatPath ? (0, history_1.interpolatePath)(formatPath, params || {}) : null;
33
+ const { params, path, hash, name, query } = to;
34
+ const search = query ? `?${qs_1.default.stringify(query)}` : '';
35
+ const formatHash = hash ? (hash.startsWith('#') ? hash : `#${hash}`) : '';
36
+ const formatPath = name ? (_a = history_1.pathNameList.find((item) => item.name === name)) === null || _a === void 0 ? void 0 : _a.path : path;
37
+ let newPath = formatPath ? (0, history_1.interpolatePath)(formatPath, params || {}) : null;
51
38
  newPath = newPath + search + formatHash;
52
39
  return newPath;
53
40
  };
54
- var useNav = function () {
55
- var navigate = (0, react_router_dom_1.useNavigate)();
56
- var newNavigate = function (to, options) {
41
+ const useNav = () => {
42
+ const navigate = (0, react_router_dom_1.useNavigate)();
43
+ const newNavigate = (to, options) => {
57
44
  switch (typeof to) {
58
45
  case 'string':
59
46
  navigate(to, options);
@@ -62,10 +49,10 @@ var useNav = function () {
62
49
  navigate(to);
63
50
  break;
64
51
  case 'object':
65
- navigate(getFormatNavPath(to), __assign(__assign({}, (options || {})), { state: to.state }));
52
+ navigate(getFormatNavPath(to), Object.assign(Object.assign({}, (options || {})), { state: to.state }));
66
53
  break;
67
54
  default:
68
- throw "An error occurred while executing useNav() operation: unexpected type of 'to':".concat(typeof to);
55
+ throw `An error occurred while executing useNav() operation: unexpected type of 'to':${typeof to}`;
69
56
  }
70
57
  };
71
58
  return newNavigate;