Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b718dd3b03 | |||
| ff2f20aebe | |||
| 1e76d60284 | |||
| 612f326515 | |||
| fcb72a4547 | |||
| a028c2b767 | |||
| 8ea30cb9a0 | |||
| f6f5eab087 | |||
| 1a7309dc38 | |||
| 60300a769b | |||
| ed64c788d5 | |||
| c19d5fc0de | |||
|
|
f2209f6708 | ||
|
|
753eaada75 | ||
| fe6d5df006 | |||
| d5e08e4178 | |||
| 14e5c02a03 | |||
| ac1e2a4df3 | |||
|
|
0636ce1ff2 | ||
|
|
47839a963c | ||
|
|
3683151cb2 | ||
|
|
033865105f | ||
|
|
556c31c56c | ||
|
|
a008842899 | ||
|
|
84cf7b72a0 | ||
|
|
03eec8c836 | ||
|
|
1f045701bf | ||
|
|
a64221d659 |
54
dist/index.js
vendored
54
dist/index.js
vendored
File diff suppressed because one or more lines are too long
11
package.json
11
package.json
@@ -1,15 +1,14 @@
|
||||
{
|
||||
"name": "fire.app",
|
||||
"version": "1.0.1",
|
||||
"name": "@ijl/fire.app",
|
||||
"version": "1.4.5",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"start": "nodemon ./stubs/server.js",
|
||||
"build": "webpack --mode development",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"build": "webpack --mode development"
|
||||
},
|
||||
"author": "innoavvlasov@gmail.com",
|
||||
"license": "MIT",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@types/node": "13.7.0",
|
||||
"@types/systemjs": "6.1.0",
|
||||
|
||||
6
src/history.ts
Normal file
6
src/history.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { createBrowserHistory } from 'history'
|
||||
|
||||
|
||||
const history = createBrowserHistory();
|
||||
|
||||
export default history;
|
||||
50
src/main.ts
50
src/main.ts
@@ -1,11 +1,11 @@
|
||||
import "systemjs/dist/s";
|
||||
import "systemjs/dist/system";
|
||||
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(
|
||||
@@ -14,50 +14,38 @@ const systemJSImport = async (requestUrl: string) => {
|
||||
return { component, mount, unmount }
|
||||
}
|
||||
|
||||
// const defaultNavigations = {
|
||||
// login: '/login',
|
||||
// main: '/main',
|
||||
// news: '/news',
|
||||
// org: '/org',
|
||||
// sections: '/sections',
|
||||
// 'news.details': '/news/{{id}}',
|
||||
// 'org.details': '/org/{{name}}',
|
||||
// 'sections.details': '/sections/{{name}}'
|
||||
// }
|
||||
|
||||
// const defaultApps = {
|
||||
// login: { version: '1.0.0', name: 'login' },
|
||||
// main: { version: '1.0.1', name: 'main' },
|
||||
// news: { version: '1.0.0', name: 'news' },
|
||||
// org: { version: '1.0.0', name: 'org' },
|
||||
// sections: { version: '1.0.0', name: 'sections' }
|
||||
// }
|
||||
|
||||
export default async ({ apps: rawApps, navigations, config }) => {
|
||||
defineVirtualModule({navigations, config})
|
||||
export default async ({ apps: rawApps, navigations, config, features }) => {
|
||||
defineVirtualModule({ navigations, config, features })
|
||||
|
||||
const apps = new Apps(rawApps)
|
||||
|
||||
const history = createBrowserHistory()
|
||||
|
||||
let prevPathname = window.location.pathname
|
||||
|
||||
const app = apps.findApp(history.location.pathname)
|
||||
async function getApp() {
|
||||
const app = apps.findApp(history.location.pathname)
|
||||
|
||||
const publicPath = `/${app.name}/${app.version}`
|
||||
const publicPath = `/${app.name}/${app.version}`
|
||||
|
||||
__webpack_public_path__ = `${config.baseUrl}${publicPath}${__webpack_public_path__}`
|
||||
__webpack_public_path__ = `${config.baseUrl}${publicPath}${__webpack_public_path__}`
|
||||
|
||||
const appPath = `${config.baseUrl}${publicPath}/index.js`
|
||||
const appPath = `${config.baseUrl}${publicPath}/index.js`
|
||||
|
||||
const { component, mount, unmount } = await systemJSImport(appPath);
|
||||
const { component, mount, unmount } = await systemJSImport(appPath);
|
||||
|
||||
return { component, mount, unmount };
|
||||
}
|
||||
|
||||
let { component, mount, unmount } = await getApp()
|
||||
mount(component.default);
|
||||
|
||||
history.listen((location) => {
|
||||
history.listen(async (location) => {
|
||||
if (location.pathname !== prevPathname) {
|
||||
prevPathname = location.pathname
|
||||
unmount()
|
||||
|
||||
const nextApp = await getApp();
|
||||
nextApp.mount(nextApp.component.default)
|
||||
unmount = nextApp.unmount;
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
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],
|
||||
getHistory: () => history,
|
||||
})
|
||||
|
||||
export const defineVirtualModule = (params) => {
|
||||
const virtualModule = createVirtualModule(params)
|
||||
// @ts-ignore
|
||||
global.define('root.scope.env', [], virtualModule)
|
||||
System.set('root.scope', {
|
||||
...virtualModule
|
||||
});
|
||||
}
|
||||
|
||||
const createVirtualModule = ({config, navigations}) => ({
|
||||
getConfig: () => config,
|
||||
getConfigValue: (key) => config[key],
|
||||
getNavigations: () => navigations,
|
||||
getNavigationsValue: (key) => navigations[key],
|
||||
})
|
||||
@@ -4,15 +4,6 @@
|
||||
"dom",
|
||||
"es7"
|
||||
],
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"*": [
|
||||
"*",
|
||||
"src/*",
|
||||
"lib/*",
|
||||
"dist/*"
|
||||
]
|
||||
},
|
||||
"outDir": "./dist/",
|
||||
"sourceMap": true,
|
||||
"esModuleInterop": true,
|
||||
|
||||
@@ -11,10 +11,10 @@ module.exports = {
|
||||
index: "./src/main.ts"
|
||||
},
|
||||
output: {
|
||||
library: "bootstrap",
|
||||
library: "fireapp",
|
||||
path: path.resolve(__dirname, outputDirectory),
|
||||
libraryExport: "default",
|
||||
publicPath: `/boorstrap/${pkg.version}/`
|
||||
publicPath: `/fireapp/${pkg.version}/`
|
||||
},
|
||||
|
||||
plugins: [new CleanWebpackPlugin()],
|
||||
|
||||
Reference in New Issue
Block a user