Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
e2855a4a4d | |||
a7fd8a4089 | |||
8213db9cfd | |||
c7ddae4b86 | |||
d94d9e03cf | |||
1ae0790319 | |||
729addc469 | |||
b718dd3b03 | |||
ff2f20aebe | |||
1e76d60284 | |||
612f326515 | |||
fcb72a4547 | |||
a028c2b767 | |||
8ea30cb9a0 | |||
f6f5eab087 | |||
1a7309dc38 | |||
60300a769b | |||
ed64c788d5 | |||
c19d5fc0de | |||
|
f2209f6708 | ||
|
753eaada75 | ||
fe6d5df006 | |||
d5e08e4178 | |||
14e5c02a03 |
4
.eslintignore
Normal file
4
.eslintignore
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.eslintrc.js
|
||||||
|
babel.config.js
|
||||||
|
webpack.config.js
|
||||||
|
dist/
|
22
.eslintrc.js
Normal file
22
.eslintrc.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
browser: true,
|
||||||
|
es2021: true
|
||||||
|
},
|
||||||
|
extends: [
|
||||||
|
'eslint:recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended'
|
||||||
|
],
|
||||||
|
overrides: [
|
||||||
|
],
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 'latest',
|
||||||
|
sourceType: 'module'
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
'@typescript-eslint'
|
||||||
|
],
|
||||||
|
rules: {
|
||||||
|
}
|
||||||
|
}
|
6
babel.config.js
Normal file
6
babel.config.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
presets: [
|
||||||
|
'@babel/preset-env',
|
||||||
|
'@babel/preset-typescript'
|
||||||
|
]
|
||||||
|
}
|
266
dist/index.js
vendored
266
dist/index.js
vendored
File diff suppressed because one or more lines are too long
1
dist/index.js.LICENSE.txt
vendored
Normal file
1
dist/index.js.LICENSE.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
10003
package-lock.json
generated
Normal file
10003
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@ -1,31 +1,36 @@
|
|||||||
{
|
{
|
||||||
"name": "@ijl/fire.app",
|
"name": "@ijl/fire.app",
|
||||||
"version": "1.1.0",
|
"version": "1.6.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "nodemon ./stubs/server.js",
|
"start": "nodemon ./stubs/server.js",
|
||||||
"build": "webpack --mode development",
|
"build": "webpack --mode development",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"build:prod": "webpack --mode production"
|
||||||
},
|
},
|
||||||
"author": "innoavvlasov@gmail.com",
|
"author": "innoavvlasov@gmail.com",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "13.7.0",
|
"@babel/core": "^7.21.0",
|
||||||
|
"@babel/preset-env": "^7.20.2",
|
||||||
|
"@babel/preset-typescript": "^7.21.0",
|
||||||
|
"@types/node": "16.18.12",
|
||||||
"@types/systemjs": "6.1.0",
|
"@types/systemjs": "6.1.0",
|
||||||
"awesome-typescript-loader": "5.2.1",
|
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
||||||
|
"@typescript-eslint/parser": "^5.53.0",
|
||||||
|
"babel-loader": "^9.1.2",
|
||||||
"clean-webpack-plugin": "3.0.0",
|
"clean-webpack-plugin": "3.0.0",
|
||||||
"es6-promise": "4.2.8",
|
"es6-promise": "4.2.8",
|
||||||
|
"eslint": "^8.34.0",
|
||||||
"exports-loader": "0.7.0",
|
"exports-loader": "0.7.0",
|
||||||
"fbjs": "1.0.0",
|
"fbjs": "1.0.0",
|
||||||
"file-loader": "5.0.2",
|
|
||||||
"history": "4.10.1",
|
"history": "4.10.1",
|
||||||
"imports-loader": "0.8.0",
|
"imports-loader": "0.8.0",
|
||||||
|
"nodemon": "^2.0.20",
|
||||||
"rimraf": "3.0.1",
|
"rimraf": "3.0.1",
|
||||||
"systemjs": "6.2.2",
|
"systemjs": "6.2.2",
|
||||||
"typescript": "3.7.5",
|
"typescript": "^4.9.5",
|
||||||
"webpack": "4.41.5",
|
"webpack": "^5.75.0",
|
||||||
"webpack-cli": "3.3.10",
|
"webpack-cli": "^5.0.1"
|
||||||
"whatwg-fetch": "3.0.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;
|
48
src/main.ts
48
src/main.ts
@ -1,11 +1,14 @@
|
|||||||
|
/* eslint-disable prefer-const */
|
||||||
import "systemjs/dist/system";
|
import "systemjs/dist/system";
|
||||||
import "systemjs/dist/extras/amd";
|
import "systemjs/dist/extras/amd";
|
||||||
import "systemjs/dist/extras/named-register";
|
import "systemjs/dist/extras/named-register";
|
||||||
import "systemjs/dist/extras/named-exports";
|
import "systemjs/dist/extras/named-exports";
|
||||||
import "systemjs/dist/extras/transform";
|
import "systemjs/dist/extras/transform";
|
||||||
import { createBrowserHistory } from 'history'
|
import "regenerator-runtime/runtime";
|
||||||
|
|
||||||
import { Apps } from './apps'
|
import { Apps } from './apps'
|
||||||
import { defineVirtualModule } from './virtual-module'
|
import { defineVirtualModule } from './virtual-module'
|
||||||
|
import history from './history';
|
||||||
|
|
||||||
const systemJSImport = async (requestUrl: string) => {
|
const systemJSImport = async (requestUrl: string) => {
|
||||||
const { default: component, mount, unmount } = await System.import(
|
const { default: component, mount, unmount } = await System.import(
|
||||||
@ -14,34 +17,23 @@ const systemJSImport = async (requestUrl: string) => {
|
|||||||
return { component, mount, unmount }
|
return { component, mount, unmount }
|
||||||
}
|
}
|
||||||
|
|
||||||
// const defaultNavigations = {
|
let mainMountElement = document.getElementById('app');
|
||||||
// login: '/login',
|
|
||||||
// main: '/main',
|
|
||||||
// news: '/news',
|
|
||||||
// org: '/org',
|
|
||||||
// sections: '/sections',
|
|
||||||
// 'news.details': '/news/{{id}}',
|
|
||||||
// 'org.details': '/org/{{name}}',
|
|
||||||
// 'sections.details': '/sections/{{name}}'
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const defaultApps = {
|
if (!mainMountElement) {
|
||||||
// login: { version: '1.0.0', name: 'login' },
|
mainMountElement = document.createElement('div');
|
||||||
// main: { version: '1.0.1', name: 'main' },
|
mainMountElement.id = 'app';
|
||||||
// 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 }) => {
|
document.body.append(mainMountElement);
|
||||||
defineVirtualModule({ navigations, config })
|
}
|
||||||
|
|
||||||
|
export default async ({ apps: rawApps, navigations, config, features }) => {
|
||||||
|
defineVirtualModule({ navigations, config, features })
|
||||||
|
|
||||||
const apps = new Apps(rawApps)
|
const apps = new Apps(rawApps)
|
||||||
|
|
||||||
const history = createBrowserHistory()
|
|
||||||
|
|
||||||
let prevPathname = window.location.pathname
|
let prevPathname = window.location.pathname
|
||||||
|
|
||||||
|
async function getApp() {
|
||||||
const app = apps.findApp(history.location.pathname)
|
const app = apps.findApp(history.location.pathname)
|
||||||
|
|
||||||
const publicPath = `/${app.name}/${app.version}`
|
const publicPath = `/${app.name}/${app.version}`
|
||||||
@ -52,12 +44,20 @@ export default async ({ apps: rawApps, navigations, config }) => {
|
|||||||
|
|
||||||
const { component, mount, unmount } = await systemJSImport(appPath);
|
const { component, mount, unmount } = await systemJSImport(appPath);
|
||||||
|
|
||||||
mount(component.default);
|
return { component, mount, unmount };
|
||||||
|
}
|
||||||
|
|
||||||
history.listen((location) => {
|
let { component, mount, unmount } = await getApp()
|
||||||
|
mount(component.default, mainMountElement);
|
||||||
|
|
||||||
|
history.listen(async (location) => {
|
||||||
if (location.pathname !== prevPathname) {
|
if (location.pathname !== prevPathname) {
|
||||||
prevPathname = location.pathname
|
prevPathname = location.pathname
|
||||||
unmount()
|
unmount()
|
||||||
|
|
||||||
|
const nextApp = await getApp();
|
||||||
|
nextApp.mount(nextApp.component.default, mainMountElement)
|
||||||
|
unmount = nextApp.unmount;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
const createVirtualModule = ({ config, navigations }) => ({
|
import history from './history';
|
||||||
|
|
||||||
|
const createVirtualModule = ({ config, navigations, features }) => ({
|
||||||
getConfig: () => config,
|
getConfig: () => config,
|
||||||
getConfigValue: (key) => config[key],
|
getConfigValue: (pkg: string) => config[pkg],
|
||||||
getNavigations: () => navigations,
|
getNavigations: () => navigations,
|
||||||
getNavigationsValue: (key) => navigations[key],
|
getNavigationsValue: (pkg: string) => navigations[pkg],
|
||||||
|
getAllFeatures: () => features,
|
||||||
|
getFeatures: (pkg: string) => features[pkg],
|
||||||
|
getHistory: () => history,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const defineVirtualModule = (params) => {
|
export const defineVirtualModule = (params) => {
|
||||||
const virtualModule = createVirtualModule(params)
|
const virtualModule = createVirtualModule(params)
|
||||||
// @ts-ignore
|
|
||||||
System.set('root.scope', {
|
System.set('root.scope', {
|
||||||
...virtualModule
|
...virtualModule
|
||||||
});
|
});
|
||||||
|
@ -2,26 +2,20 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"lib": [
|
"lib": [
|
||||||
"dom",
|
"dom",
|
||||||
"es7"
|
"ESNext"
|
||||||
],
|
],
|
||||||
"baseUrl": ".",
|
|
||||||
"paths": {
|
|
||||||
"*": [
|
|
||||||
"*",
|
|
||||||
"src/*",
|
|
||||||
"lib/*",
|
|
||||||
"dist/*"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"outDir": "./dist/",
|
"outDir": "./dist/",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"downlevelIteration" :true,
|
"downlevelIteration": true,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"target": "es6",
|
"target": "es6",
|
||||||
"jsx": "react",
|
"typeRoots": [
|
||||||
"typeRoots": ["node_modules/@types", "src/typings", "../../node_modules/@types"]
|
"node_modules/@types",
|
||||||
|
"src/typings",
|
||||||
|
"../../node_modules/@types"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules"
|
"node_modules"
|
||||||
|
@ -6,21 +6,20 @@ const outputDirectory = 'dist';
|
|||||||
const pkg = require('./package.json')
|
const pkg = require('./package.json')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mode: "development",
|
|
||||||
entry: {
|
entry: {
|
||||||
index: "./src/main.ts"
|
index: './src/main.ts'
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
library: "bootstrap",
|
library: 'fireapp',
|
||||||
path: path.resolve(__dirname, outputDirectory),
|
path: path.resolve(__dirname, outputDirectory),
|
||||||
libraryExport: "default",
|
libraryExport: 'default',
|
||||||
publicPath: `/boorstrap/${pkg.version}/`
|
publicPath: `/fireapp/${pkg.version}/`
|
||||||
},
|
},
|
||||||
|
|
||||||
plugins: [new CleanWebpackPlugin()],
|
plugins: [new CleanWebpackPlugin()],
|
||||||
|
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: [".ts", ".js"]
|
extensions: ['.ts', '.js']
|
||||||
},
|
},
|
||||||
|
|
||||||
module: {
|
module: {
|
||||||
@ -28,11 +27,7 @@ module.exports = {
|
|||||||
{ parser: { system: false } },
|
{ parser: { system: false } },
|
||||||
{
|
{
|
||||||
test: /\.tsx?$/,
|
test: /\.tsx?$/,
|
||||||
loader: "awesome-typescript-loader"
|
loader: 'babel-loader'
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.(jpe?g|gif|png|svg|woff|ttf|eot|wav|mp3)$/,
|
|
||||||
loader: "file-loader"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user