From a907153d8b4f91a27145df042365df39f405bdb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=BC=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Sat, 28 Mar 2020 18:17:05 +0300 Subject: [PATCH] =?UTF-8?q?=5F=5Fwebpack=5Fpublic=5Fpath=5F=5F=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/index.js | 2 +- src/main.ts | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dist/index.js b/dist/index.js index 823798e..edbae29 100644 --- a/dist/index.js +++ b/dist/index.js @@ -233,7 +233,7 @@ eval("var g;\n\n// This works in non-strict mode\ng = (function() {\n\treturn th /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\n__webpack_require__(/*! systemjs/dist/s */ \"./node_modules/systemjs/dist/s.js\");\n__webpack_require__(/*! systemjs/dist/extras/amd */ \"./node_modules/systemjs/dist/extras/amd.js\");\n__webpack_require__(/*! systemjs/dist/extras/named-register */ \"./node_modules/systemjs/dist/extras/named-register.js\");\n__webpack_require__(/*! systemjs/dist/extras/named-exports */ \"./node_modules/systemjs/dist/extras/named-exports.js\");\n__webpack_require__(/*! systemjs/dist/extras/transform */ \"./node_modules/systemjs/dist/extras/transform.js\");\nconst history_1 = __webpack_require__(/*! history */ \"./node_modules/history/esm/history.js\");\nconst systemJSImport = (requestUrl) => __awaiter(void 0, void 0, void 0, function* () {\n const { default: component, mount, unmount } = yield System.import(requestUrl);\n return { component, mount, unmount };\n});\nclass Apps extends Map {\n constructor(apps) {\n super();\n this.findApp = (path) => {\n const currentPath = [...this.keys()].reduce((memo, appRoute) => {\n const correctedAppRoute = appRoute.replace(/^\\/?/, '/');\n const correctedMemo = memo ? memo.replace(/^\\/?/, '/') : memo;\n return this.startWithPath(path, correctedAppRoute) && this.startWithPath(correctedAppRoute, correctedMemo)\n ? appRoute\n : memo;\n }, void 0);\n return (this.get(currentPath) || this.get('/') || {\n version: ''\n });\n };\n this.merge(apps);\n }\n merge(apps) {\n (Object.entries(apps).forEach(([path, options]) => this.set(path, options)));\n }\n startWithPath(path, subPath) {\n if (!subPath) {\n return true;\n }\n const pathItem = String(path).split('/');\n const subPathItems = String(subPath).split('/');\n return subPathItems.reduce((memo, appItem, index) => memo && pathItem[index] === appItem, true);\n }\n}\nconst defaultNavigations = {\n login: '/login',\n main: '/main',\n news: '/news',\n org: '/org',\n sections: '/sections',\n 'news.details': '/news/{{id}}',\n 'org.details': '/org/{{name}}',\n 'sections.details': '/sections/{{name}}'\n};\nconst defaultApps = {\n login: { version: '1.0.0' },\n main: { version: '1.0.1', name: 'main' },\n news: { version: '1.0.0' },\n org: { version: '1.0.0' },\n sections: { version: '1.0.0' }\n};\nexports.default = ({ rawapps = defaultApps, navigations = defaultNavigations, config }) => __awaiter(void 0, void 0, void 0, function* () {\n const apps = new Apps(rawapps);\n const history = history_1.createBrowserHistory();\n let prevPathname = window.location.pathname;\n const app = apps.findApp(history.location.pathname);\n // console.log('publicPath', publicPath)\n const publicPath = `./${app.name}/${app.version}`;\n __webpack_require__.p = `${publicPath}${__webpack_require__.p}`;\n const appPath = `${config.baseUrl}/${publicPath}/index.js`;\n const { component, mount, unmount } = yield systemJSImport(appPath);\n mount(component.default);\n history.listen((location) => {\n if (location.pathname !== prevPathname) {\n prevPathname = location.pathname;\n unmount();\n }\n });\n});\n\n\n//# sourceURL=webpack://bootstrap/./src/main.ts?"); +eval("\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\n__webpack_require__(/*! systemjs/dist/s */ \"./node_modules/systemjs/dist/s.js\");\n__webpack_require__(/*! systemjs/dist/extras/amd */ \"./node_modules/systemjs/dist/extras/amd.js\");\n__webpack_require__(/*! systemjs/dist/extras/named-register */ \"./node_modules/systemjs/dist/extras/named-register.js\");\n__webpack_require__(/*! systemjs/dist/extras/named-exports */ \"./node_modules/systemjs/dist/extras/named-exports.js\");\n__webpack_require__(/*! systemjs/dist/extras/transform */ \"./node_modules/systemjs/dist/extras/transform.js\");\nconst history_1 = __webpack_require__(/*! history */ \"./node_modules/history/esm/history.js\");\nconst systemJSImport = (requestUrl) => __awaiter(void 0, void 0, void 0, function* () {\n const { default: component, mount, unmount } = yield System.import(requestUrl);\n return { component, mount, unmount };\n});\nclass Apps extends Map {\n constructor(apps) {\n super();\n this.findApp = (path) => {\n const currentPath = [...this.keys()].reduce((memo, appRoute) => {\n const correctedAppRoute = appRoute.replace(/^\\/?/, '/');\n const correctedMemo = memo ? memo.replace(/^\\/?/, '/') : memo;\n return this.startWithPath(path, correctedAppRoute) && this.startWithPath(correctedAppRoute, correctedMemo)\n ? appRoute\n : memo;\n }, void 0);\n return (this.get(currentPath) || this.get('/') || {\n version: ''\n });\n };\n this.merge(apps);\n }\n merge(apps) {\n (Object.entries(apps).forEach(([path, options]) => this.set(path, options)));\n }\n startWithPath(path, subPath) {\n if (!subPath) {\n return true;\n }\n const pathItem = String(path).split('/');\n const subPathItems = String(subPath).split('/');\n return subPathItems.reduce((memo, appItem, index) => memo && pathItem[index] === appItem, true);\n }\n}\nconst defaultNavigations = {\n login: '/login',\n main: '/main',\n news: '/news',\n org: '/org',\n sections: '/sections',\n 'news.details': '/news/{{id}}',\n 'org.details': '/org/{{name}}',\n 'sections.details': '/sections/{{name}}'\n};\nconst defaultApps = {\n login: { version: '1.0.0' },\n main: { version: '1.0.1', name: 'main' },\n news: { version: '1.0.0' },\n org: { version: '1.0.0' },\n sections: { version: '1.0.0' }\n};\nexports.default = ({ apps: rowApps, navigations, config }) => __awaiter(void 0, void 0, void 0, function* () {\n const apps = new Apps(rowApps);\n const history = history_1.createBrowserHistory();\n let prevPathname = window.location.pathname;\n const app = apps.findApp(history.location.pathname);\n const publicPath = `/${app.name}/${app.version}`;\n __webpack_require__.p = `${config.baseUrl}${publicPath}${__webpack_require__.p}`;\n const appPath = `${config.baseUrl}${publicPath}/index.js`;\n const { component, mount, unmount } = yield systemJSImport(appPath);\n mount(component.default);\n history.listen((location) => {\n if (location.pathname !== prevPathname) {\n prevPathname = location.pathname;\n unmount();\n }\n });\n});\n\n\n//# sourceURL=webpack://bootstrap/./src/main.ts?"); /***/ }) diff --git a/src/main.ts b/src/main.ts index d0d63a5..178cd49 100644 --- a/src/main.ts +++ b/src/main.ts @@ -81,24 +81,24 @@ const defaultNavigations = { } const defaultApps = { - login: { version: '1.0.0' }, + login: { version: '1.0.0', name: 'login' }, main: { version: '1.0.1', name: 'main' }, - news: { version: '1.0.0' }, - org: { version: '1.0.0' }, - sections: { version: '1.0.0' } + news: { version: '1.0.0', name: 'news' }, + org: { version: '1.0.0', name: 'org' }, + sections: { version: '1.0.0', name: 'sections' } } -export default async ({ rawapps, navigations, config }) => { - const apps = new Apps(rawapps) +export default async ({ apps: rowApps, navigations, config }) => { + const apps = new Apps(rowApps) const history = createBrowserHistory() let prevPathname = window.location.pathname const app = apps.findApp(history.location.pathname) - const publicPath = `./${app.name}/${app.version}` + const publicPath = `/${app.name}/${app.version}` - __webpack_public_path__ = `${publicPath}${__webpack_public_path__}` + __webpack_public_path__ = `${config.baseUrl}${publicPath}${__webpack_public_path__}` const appPath = `${config.baseUrl}${publicPath}/index.js`