UNPKG

zmp-vue

Version:

Build full featured iOS & Android apps using ZMP & Vue

138 lines (104 loc) 4.28 kB
"use strict"; exports.__esModule = true; exports.default = void 0; var _ssrWindow = require("ssr-window"); var _utils = require("../../common/utils"); var _constants = require("../../common/constants"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } var window = (0, _ssrWindow.getWindow)(); // eslint-disable-next-line no-var var importPages; try { if (process.env.NODE_ENV === 'production') { // eslint-disable-next-line no-undef importPages = ZMP_IMPORT_PAGES; } // eslint-disable-next-line no-empty } catch (err) {} var initRoutes = function initRoutes(routes) { var appRoutes; if (routes && importPages) { appRoutes = routes.map(function (path, index) { var _toRoutePath = (0, _utils.toRoutePath)(path), routePath = _toRoutePath.path, fileDir = _toRoutePath.fileDir; var alias; if (routePath) { alias = routePath.substring(0, routePath.length - 1); } var routeObj = { path: routePath, asyncComponent: importPages[fileDir] }; if (alias) { routeObj.alias = alias; } return routeObj; }); appRoutes = [{ path: '/', name: 'home', asyncComponent: importPages.index }].concat(appRoutes); } return appRoutes; }; var initDevRouter = function initDevRouter(routes) { if (routes) { // eslint-disable-next-line no-param-reassign routes = routes.map(function (path, index) { var _resolvePath = (0, _utils.resolvePath)(path), _resolvePath$dir = _resolvePath.dir, dir = _resolvePath$dir === void 0 ? [] : _resolvePath$dir, fileName = _resolvePath.fileName; var pathToPage = ''; if (dir.length) { pathToPage = dir.join('/') + "/"; } var _toRoutePath2 = (0, _utils.toRoutePath)(path), routePath = _toRoutePath2.path; var alias; if (routePath) { alias = routePath.substring(0, routePath.length - 1); } var routeObj = { path: routePath, asyncComponent: function asyncComponent() { return Promise.resolve("/src/" + _constants.PAGE_DIR + "/" + pathToPage + fileName + ".vue").then(function (s) { return _interopRequireWildcard(require(s)); }); } }; if (alias) { routeObj.alias = alias; } return routeObj; }); routes = [{ path: '/', asyncComponent: function asyncComponent() { return Promise.resolve("/src/" + _constants.PAGE_DIR + "/index.vue").then(function (s) { return _interopRequireWildcard(require(s)); }); } }].concat(routes); } return routes; }; var _default = function _default() { var routes; if (window.APP_CONFIG) { routes = window.APP_CONFIG.pages; } if (routes) { routes = routes.map(function (route) { return (0, _utils.standardizePageDir)(route); }); // eslint-disable-next-line no-restricted-globals if (process.env.NODE_ENV === 'production') { routes = initRoutes(routes); } else { routes = initDevRouter(routes); } } return routes; }; exports.default = _default;