diff --git a/dist/index.js b/dist/index.js index efb4c3a..2e5369e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -78,7 +78,7 @@ var fireapp = /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ -/******/ __webpack_require__.p = "/fireapp/1.4.0/"; +/******/ __webpack_require__.p = "/fireapp/1.4.2/"; /******/ /******/ /******/ // Load entry module and return exports @@ -237,6 +237,18 @@ eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nclass /***/ }), +/***/ "./src/history.ts": +/*!************************!*\ + !*** ./src/history.ts ***! + \************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst history_1 = __webpack_require__(/*! history */ \"./node_modules/history/esm/history.js\");\nconst history = history_1.createBrowserHistory();\nexports.default = history;\n\n\n//# sourceURL=webpack://fireapp/./src/history.ts?"); + +/***/ }), + /***/ "./src/main.ts": /*!*********************!*\ !*** ./src/main.ts ***! @@ -245,7 +257,7 @@ eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nclass /***/ (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/system */ \"./node_modules/systemjs/dist/system.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 apps_1 = __webpack_require__(/*! ./apps */ \"./src/apps.ts\");\nconst virtual_module_1 = __webpack_require__(/*! ./virtual-module */ \"./src/virtual-module.ts\");\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});\nexports.default = ({ apps: rawApps, navigations, config, features }) => __awaiter(void 0, void 0, void 0, function* () {\n virtual_module_1.defineVirtualModule({ navigations, config, features });\n const apps = new apps_1.Apps(rawApps);\n const history = history_1.createBrowserHistory();\n let prevPathname = window.location.pathname;\n function getApp() {\n return __awaiter(this, void 0, void 0, function* () {\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 return { component, mount, unmount };\n });\n }\n let { component, mount, unmount } = yield getApp();\n mount(component.default);\n history.listen((location) => __awaiter(void 0, void 0, void 0, function* () {\n if (location.pathname !== prevPathname) {\n prevPathname = location.pathname;\n unmount();\n const nextApp = yield getApp();\n nextApp.mount(nextApp.component.default);\n unmount = nextApp.unmount;\n }\n }));\n});\n\n\n//# sourceURL=webpack://fireapp/./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};\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\n__webpack_require__(/*! systemjs/dist/system */ \"./node_modules/systemjs/dist/system.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 apps_1 = __webpack_require__(/*! ./apps */ \"./src/apps.ts\");\nconst virtual_module_1 = __webpack_require__(/*! ./virtual-module */ \"./src/virtual-module.ts\");\nconst history_1 = __importDefault(__webpack_require__(/*! ./history */ \"./src/history.ts\"));\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});\nexports.default = ({ apps: rawApps, navigations, config, features }) => __awaiter(void 0, void 0, void 0, function* () {\n virtual_module_1.defineVirtualModule({ navigations, config, features });\n const apps = new apps_1.Apps(rawApps);\n let prevPathname = window.location.pathname;\n function getApp() {\n return __awaiter(this, void 0, void 0, function* () {\n const app = apps.findApp(history_1.default.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 return { component, mount, unmount };\n });\n }\n let { component, mount, unmount } = yield getApp();\n mount(component.default);\n history_1.default.listen((location) => __awaiter(void 0, void 0, void 0, function* () {\n if (location.pathname !== prevPathname) {\n prevPathname = location.pathname;\n unmount();\n const nextApp = yield getApp();\n nextApp.mount(nextApp.component.default);\n unmount = nextApp.unmount;\n }\n }));\n});\n\n\n//# sourceURL=webpack://fireapp/./src/main.ts?"); /***/ }), @@ -257,7 +269,7 @@ eval("\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _argument /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst createVirtualModule = ({ config, navigations, features }) => ({\n getConfig: () => config,\n getConfigValue: (pkg) => config[pkg],\n getNavigations: () => navigations,\n getNavigationsValue: (pkg) => navigations[pkg],\n getAllFeatures: () => features,\n getFeatures: (pkg) => features[pkg]\n});\nexports.defineVirtualModule = (params) => {\n const virtualModule = createVirtualModule(params);\n // @ts-ignore\n System.set('root.scope', Object.assign({}, virtualModule));\n};\n\n\n//# sourceURL=webpack://fireapp/./src/virtual-module.ts?"); +eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst history_1 = __importDefault(__webpack_require__(/*! ./history */ \"./src/history.ts\"));\nconst createVirtualModule = ({ config, navigations, features }) => ({\n getConfig: () => config,\n getConfigValue: (pkg) => config[pkg],\n getNavigations: () => navigations,\n getNavigationsValue: (pkg) => navigations[pkg],\n getAllFeatures: () => features,\n getFeatures: (pkg) => features[pkg],\n getHistory: () => history_1.default,\n});\nexports.defineVirtualModule = (params) => {\n const virtualModule = createVirtualModule(params);\n // @ts-ignore\n System.set('root.scope', Object.assign({}, virtualModule));\n};\n\n\n//# sourceURL=webpack://fireapp/./src/virtual-module.ts?"); /***/ }) diff --git a/src/history.ts b/src/history.ts new file mode 100644 index 0000000..07c4a58 --- /dev/null +++ b/src/history.ts @@ -0,0 +1,6 @@ +import { createBrowserHistory } from 'history' + + +const history = createBrowserHistory(); + +export default history; diff --git a/src/main.ts b/src/main.ts index 2755a05..89fd2c1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,9 +3,9 @@ import "systemjs/dist/extras/amd"; import "systemjs/dist/extras/named-register"; import "systemjs/dist/extras/named-exports"; import "systemjs/dist/extras/transform"; -import { createBrowserHistory } from 'history' import { Apps } from './apps' import { defineVirtualModule } from './virtual-module' +import history from './history'; const systemJSImport = async (requestUrl: string) => { const { default: component, mount, unmount } = await System.import( @@ -19,8 +19,6 @@ export default async ({ apps: rawApps, navigations, config, features }) => { const apps = new Apps(rawApps) - const history = createBrowserHistory() - let prevPathname = window.location.pathname async function getApp() { diff --git a/src/virtual-module.ts b/src/virtual-module.ts index bfaa767..70d0d67 100644 --- a/src/virtual-module.ts +++ b/src/virtual-module.ts @@ -1,10 +1,13 @@ +import history from './history'; + const createVirtualModule = ({ config, navigations, features }) => ({ getConfig: () => config, getConfigValue: (pkg: string) => config[pkg], getNavigations: () => navigations, getNavigationsValue: (pkg: string) => navigations[pkg], getAllFeatures: () => features, - getFeatures: (pkg: string) => features[pkg] + getFeatures: (pkg: string) => features[pkg], + getHistory: () => history, }) export const defineVirtualModule = (params) => { diff --git a/tsconfig.json b/tsconfig.json index 69bbda2..db54eae 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,15 +4,6 @@ "dom", "es7" ], - "baseUrl": ".", - "paths": { - "*": [ - "*", - "src/*", - "lib/*", - "dist/*" - ] - }, "outDir": "./dist/", "sourceMap": true, "esModuleInterop": true,