diff --git a/packages/fes-plugin-qiankun/examples/app1/.env b/packages/fes-plugin-qiankun/examples/app1/.env new file mode 100644 index 00000000..e57859d2 --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/app1/.env @@ -0,0 +1 @@ +PORT=8001 diff --git a/packages/fes-plugin-qiankun/examples/app1/.eslintrc.js b/packages/fes-plugin-qiankun/examples/app1/.eslintrc.js new file mode 100644 index 00000000..6300816f --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/app1/.eslintrc.js @@ -0,0 +1,14 @@ +module.exports = { + extends: ['@webank/eslint-config-webank/vue.js'], + overrides: [ + { + files: [ + '**/__tests__/*.{j,t}s?(x)', + '**/tests/unit/**/*.spec.{j,t}s?(x)' + ] + } + ], + env: { + jest: true + } +}; diff --git a/packages/fes-plugin-qiankun/examples/app1/.fes.js b/packages/fes-plugin-qiankun/examples/app1/.fes.js new file mode 100644 index 00000000..4540b6ee --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/app1/.fes.js @@ -0,0 +1,12 @@ +// .fes.js 只负责管理编译时配置,只能使用plain Object + + +export default { + qiankun: { + micro: {} + }, + plugins: [ + require.resolve('../../../fes-plugin-model/lib'), + require.resolve('../../../fes-plugin-qiankun/lib'), + ] +}; diff --git a/packages/fes-plugin-qiankun/examples/app1/.gitignore b/packages/fes-plugin-qiankun/examples/app1/.gitignore new file mode 100644 index 00000000..df903b98 --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/app1/.gitignore @@ -0,0 +1,11 @@ +.DS_Store + +# dependencies +/node_modules +/coverage + +# fes +/src/.fes +/src/.fes-production +/src/.fes-test +/.env.local diff --git a/packages/fes-plugin-qiankun/examples/app1/LICENSE b/packages/fes-plugin-qiankun/examples/app1/LICENSE new file mode 100644 index 00000000..0978fbf7 --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/app1/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020-present webank + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/packages/fes-plugin-qiankun/examples/app1/package.json b/packages/fes-plugin-qiankun/examples/app1/package.json new file mode 100644 index 00000000..15bb6521 --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/app1/package.json @@ -0,0 +1,54 @@ +{ + "name": "app1", + "version": "2.0.0", + "description": "fes项目模版", + "scripts": { + "build": "fes build", + "prod": "FES_ENV=prod fes build", + "analyze": "ANALYZE=1 fes build", + "dev": "fes dev", + "test": "fes test" + }, + "keywords": [ + "管理端", + "fes", + "fast", + "easy", + "strong" + ], + "files": [ + ".eslintrc.js", + ".gitignore", + ".fes.js", + ".fes.prod.js", + "mock.js", + "package.json", + "README.md", + "tsconfig.json", + "/src", + "/config" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/WeBankFinTech/fes.js.git", + "directory": "packages/fes-template" + }, + "author": "harrywan", + "license": "MIT", + "bugs": { + "url": "https://github.com/WeBankFinTech/fes.js/issues" + }, + "homepage": "https://github.com/WeBankFinTech/fes.js#readme", + "publishConfig": { + "access": "public" + }, + "devDependencies": { + "@webank/eslint-config-webank": "0.2.10" + }, + "dependencies": { + "@fesjs/fes": "^2.0.0-rc.0", + "vue": "^3.0.5", + "ant-design-vue": "2.0.0" + }, + "private": true +} diff --git a/packages/fes-plugin-qiankun/examples/app1/src/app.js b/packages/fes-plugin-qiankun/examples/app1/src/app.js new file mode 100644 index 00000000..5d609f81 --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/app1/src/app.js @@ -0,0 +1,12 @@ +import PageLoading from '@/components/PageLoading'; + +export const beforeRender = { + loading: , + action() { + return new Promise((resolve) => { + setTimeout(() => { + resolve(); + }, 200); + }); + } +}; diff --git a/packages/fes-plugin-qiankun/examples/app1/src/components/PageLoading.vue b/packages/fes-plugin-qiankun/examples/app1/src/components/PageLoading.vue new file mode 100644 index 00000000..14f1165e --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/app1/src/components/PageLoading.vue @@ -0,0 +1,29 @@ + + + diff --git a/packages/fes-plugin-qiankun/examples/app1/src/global.css b/packages/fes-plugin-qiankun/examples/app1/src/global.css new file mode 100644 index 00000000..e69de29b diff --git a/packages/fes-plugin-qiankun/examples/app1/src/images/icon.png b/packages/fes-plugin-qiankun/examples/app1/src/images/icon.png new file mode 100644 index 00000000..ff46a842 Binary files /dev/null and b/packages/fes-plugin-qiankun/examples/app1/src/images/icon.png differ diff --git a/packages/fes-plugin-qiankun/examples/app1/src/pages/app1/index.vue b/packages/fes-plugin-qiankun/examples/app1/src/pages/app1/index.vue new file mode 100644 index 00000000..ef9b2005 --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/app1/src/pages/app1/index.vue @@ -0,0 +1,22 @@ + + +{ + "name": "index", + "title": "home" +} + + + + diff --git a/packages/fes-plugin-qiankun/examples/app1/src/pages/app1/test.vue b/packages/fes-plugin-qiankun/examples/app1/src/pages/app1/test.vue new file mode 100644 index 00000000..c77c3a19 --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/app1/src/pages/app1/test.vue @@ -0,0 +1,22 @@ + + +{ + "name": "index", + "title": "home" +} + + + + diff --git a/packages/fes-plugin-qiankun/examples/app1/tsconfig.json b/packages/fes-plugin-qiankun/examples/app1/tsconfig.json new file mode 100644 index 00000000..ea930c0b --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/app1/tsconfig.json @@ -0,0 +1,37 @@ +{ + "compilerOptions": { + "outDir": "build/dist", + "module": "esnext", + "target": "esnext", + "lib": ["esnext", "dom"], + "sourceMap": true, + "baseUrl": ".", + "jsx": "preserve", + "allowSyntheticDefaultImports": true, + "moduleResolution": "node", + "forceConsistentCasingInFileNames": true, + "noImplicitReturns": true, + "suppressImplicitAnyIndexErrors": true, + "noUnusedLocals": true, + "allowJs": true, + "skipLibCheck": true, + "experimentalDecorators": true, + "strict": true, + "paths": { + "@/*": ["./src/*"], + "@@/*": ["./src/.fes/*"] + } + }, + "include": [ + "src/**/*", + "tests/**/*", + "test/**/*", + "__test__/**/*", + "typings/**/*", + "config/**/*", + ".eslintrc.js", + ".stylelintrc.js", + ".prettierrc.js" + ], + "exclude": ["node_modules", "build", "dist", "scripts", "src/.fes/*", "webpack", "jest"] +} diff --git a/packages/fes-plugin-qiankun/examples/main/.env b/packages/fes-plugin-qiankun/examples/main/.env new file mode 100644 index 00000000..3646d14f --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/main/.env @@ -0,0 +1 @@ +PORT=8000 diff --git a/packages/fes-plugin-qiankun/examples/main/.eslintrc.js b/packages/fes-plugin-qiankun/examples/main/.eslintrc.js new file mode 100644 index 00000000..6300816f --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/main/.eslintrc.js @@ -0,0 +1,14 @@ +module.exports = { + extends: ['@webank/eslint-config-webank/vue.js'], + overrides: [ + { + files: [ + '**/__tests__/*.{j,t}s?(x)', + '**/tests/unit/**/*.spec.{j,t}s?(x)' + ] + } + ], + env: { + jest: true + } +}; diff --git a/packages/fes-plugin-qiankun/examples/main/.fes.js b/packages/fes-plugin-qiankun/examples/main/.fes.js new file mode 100644 index 00000000..e9f8587c --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/main/.fes.js @@ -0,0 +1,45 @@ +// .fes.js 只负责管理编译时配置,只能使用plain Object + + +export default { + access: { + roles: { + admin: ["*"] + } + }, + layout: { + title: "Fes.js", + footer: 'Created by MumbelFe', + multiTabs: false, + navigation: 'mixin', + menus: [{ + name: 'index', + icon: 'user' + }, { + title: "子应用1", + icon: 'user', + children: [{ + name: 'app1-index' + },{ + name: 'app1-test' + }] + }] + }, + qiankun: { + main: { + apps: [ + { + name: 'app1', // 唯一 id + entry: '//localhost:8001', // html entry + props: {} // 传递给子应用的数据 + } + ] + } + }, + plugins: [ + require.resolve('../../../fes-plugin-model/lib'), + require.resolve('../../../fes-plugin-layout/lib'), + require.resolve('../../../fes-plugin-access/lib'), + require.resolve('../../../fes-plugin-qiankun/lib'), + ] +}; diff --git a/packages/fes-plugin-qiankun/examples/main/.gitignore b/packages/fes-plugin-qiankun/examples/main/.gitignore new file mode 100644 index 00000000..df903b98 --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/main/.gitignore @@ -0,0 +1,11 @@ +.DS_Store + +# dependencies +/node_modules +/coverage + +# fes +/src/.fes +/src/.fes-production +/src/.fes-test +/.env.local diff --git a/packages/fes-plugin-qiankun/examples/main/LICENSE b/packages/fes-plugin-qiankun/examples/main/LICENSE new file mode 100644 index 00000000..0978fbf7 --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/main/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020-present webank + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/packages/fes-plugin-qiankun/examples/main/package.json b/packages/fes-plugin-qiankun/examples/main/package.json new file mode 100644 index 00000000..9864aa90 --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/main/package.json @@ -0,0 +1,54 @@ +{ + "name": "main", + "version": "2.0.0", + "description": "fes项目模版", + "scripts": { + "build": "fes build", + "prod": "FES_ENV=prod fes build", + "analyze": "ANALYZE=1 fes build", + "dev": "fes dev", + "test": "fes test" + }, + "keywords": [ + "管理端", + "fes", + "fast", + "easy", + "strong" + ], + "files": [ + ".eslintrc.js", + ".gitignore", + ".fes.js", + ".fes.prod.js", + "mock.js", + "package.json", + "README.md", + "tsconfig.json", + "/src", + "/config" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/WeBankFinTech/fes.js.git", + "directory": "packages/fes-template" + }, + "author": "harrywan", + "license": "MIT", + "bugs": { + "url": "https://github.com/WeBankFinTech/fes.js/issues" + }, + "homepage": "https://github.com/WeBankFinTech/fes.js#readme", + "publishConfig": { + "access": "public" + }, + "devDependencies": { + "@webank/eslint-config-webank": "0.2.10" + }, + "dependencies": { + "@fesjs/fes": "^2.0.0-rc.0", + "vue": "^3.0.5", + "ant-design-vue": "2.0.0" + }, + "private": true +} diff --git a/packages/fes-plugin-qiankun/examples/main/src/app.js b/packages/fes-plugin-qiankun/examples/main/src/app.js new file mode 100644 index 00000000..52361d60 --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/main/src/app.js @@ -0,0 +1,15 @@ +import { access as accessApi } from '@fesjs/fes'; +import PageLoading from '@/components/PageLoading'; + +export const beforeRender = { + loading: , + action() { + const { setRole } = accessApi; + return new Promise((resolve) => { + setTimeout(() => { + setRole('admin'); + resolve(); + }, 1000); + }); + } +}; diff --git a/packages/fes-plugin-qiankun/examples/main/src/components/PageLoading.vue b/packages/fes-plugin-qiankun/examples/main/src/components/PageLoading.vue new file mode 100644 index 00000000..14f1165e --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/main/src/components/PageLoading.vue @@ -0,0 +1,29 @@ + + + diff --git a/packages/fes-plugin-qiankun/examples/main/src/global.css b/packages/fes-plugin-qiankun/examples/main/src/global.css new file mode 100644 index 00000000..e69de29b diff --git a/packages/fes-plugin-qiankun/examples/main/src/images/icon.png b/packages/fes-plugin-qiankun/examples/main/src/images/icon.png new file mode 100644 index 00000000..ff46a842 Binary files /dev/null and b/packages/fes-plugin-qiankun/examples/main/src/images/icon.png differ diff --git a/packages/fes-plugin-qiankun/examples/main/src/pages/app1/index.vue b/packages/fes-plugin-qiankun/examples/main/src/pages/app1/index.vue new file mode 100644 index 00000000..1962ab55 --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/main/src/pages/app1/index.vue @@ -0,0 +1,7 @@ + +{ + "name": "app1-index", + "title": "子应用1-首页", + "microApp": "app1" +} + diff --git a/packages/fes-plugin-qiankun/examples/main/src/pages/app1/test.vue b/packages/fes-plugin-qiankun/examples/main/src/pages/app1/test.vue new file mode 100644 index 00000000..bc74c396 --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/main/src/pages/app1/test.vue @@ -0,0 +1,7 @@ + +{ + "name": "app1-test", + "title": "子应用1-测试", + "microApp": "app1" +} + diff --git a/packages/fes-plugin-qiankun/examples/main/src/pages/index.vue b/packages/fes-plugin-qiankun/examples/main/src/pages/index.vue new file mode 100644 index 00000000..e1f1c676 --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/main/src/pages/index.vue @@ -0,0 +1,11 @@ + + +{ + "name": "index", + "title": "首页" +} + diff --git a/packages/fes-plugin-qiankun/examples/main/tsconfig.json b/packages/fes-plugin-qiankun/examples/main/tsconfig.json new file mode 100644 index 00000000..ea930c0b --- /dev/null +++ b/packages/fes-plugin-qiankun/examples/main/tsconfig.json @@ -0,0 +1,37 @@ +{ + "compilerOptions": { + "outDir": "build/dist", + "module": "esnext", + "target": "esnext", + "lib": ["esnext", "dom"], + "sourceMap": true, + "baseUrl": ".", + "jsx": "preserve", + "allowSyntheticDefaultImports": true, + "moduleResolution": "node", + "forceConsistentCasingInFileNames": true, + "noImplicitReturns": true, + "suppressImplicitAnyIndexErrors": true, + "noUnusedLocals": true, + "allowJs": true, + "skipLibCheck": true, + "experimentalDecorators": true, + "strict": true, + "paths": { + "@/*": ["./src/*"], + "@@/*": ["./src/.fes/*"] + } + }, + "include": [ + "src/**/*", + "tests/**/*", + "test/**/*", + "__test__/**/*", + "typings/**/*", + "config/**/*", + ".eslintrc.js", + ".stylelintrc.js", + ".prettierrc.js" + ], + "exclude": ["node_modules", "build", "dist", "scripts", "src/.fes/*", "webpack", "jest"] +} diff --git a/packages/fes-plugin-qiankun/package.json b/packages/fes-plugin-qiankun/package.json index d5d3b761..75cf70bf 100644 --- a/packages/fes-plugin-qiankun/package.json +++ b/packages/fes-plugin-qiankun/package.json @@ -7,7 +7,9 @@ "lib" ], "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "start": "npm-run-all --parallel start:*", + "start:master": "cd ./examples/main && fes dev", + "start:app1": "cd ./examples/app1 && fes dev" }, "repository": { "type": "git", @@ -32,6 +34,9 @@ "lodash": "^4.17.15", "qiankun": "2.3.4" }, + "devDependencies": { + "npm-run-all": "^4.1.5" + }, "peerDependencies": { "@webank/fes": "^2.0.0-rc.0", "vue": "^3.0.5" diff --git a/packages/fes-plugin-qiankun/src/main/modifyRoutes.js b/packages/fes-plugin-qiankun/src/main/modifyRoutes.js index 8a1ff4e0..e113728b 100644 --- a/packages/fes-plugin-qiankun/src/main/modifyRoutes.js +++ b/packages/fes-plugin-qiankun/src/main/modifyRoutes.js @@ -2,11 +2,11 @@ import { defaultHistoryType } from '../constants'; function getMicroApp(options) { const { - microAppName, masterHistoryType, base, namespace, ...normalizedRouteProps + key, microAppName, masterHistoryType, base, namespace, ...normalizedRouteProps } = options; return `(() => { const { getMicroAppRouteComponent } = require('@@/${namespace}/getMicroAppRouteComponent'); -return getMicroAppRouteComponent({ appName: '${microAppName}', base: '${base}', masterHistoryType: '${masterHistoryType}', routeProps: ${JSON.stringify(normalizedRouteProps)} }) +return getMicroAppRouteComponent({key: '${key}', appName: '${microAppName}', base: '${base}', masterHistoryType: '${masterHistoryType}', routeProps: ${JSON.stringify(normalizedRouteProps)} }) })()`; } @@ -18,6 +18,7 @@ function modifyRoutesWithAttachMode({ _routes.forEach((route) => { if (route.meta && route.meta.microApp) { route.component = getMicroApp({ + key: route.path, microAppName: route.meta.microApp, masterHistoryType, base, diff --git a/packages/fes-plugin-qiankun/src/main/runtime/MicroApp.tpl b/packages/fes-plugin-qiankun/src/main/runtime/MicroApp.tpl index c4804697..9c642047 100644 --- a/packages/fes-plugin-qiankun/src/main/runtime/MicroApp.tpl +++ b/packages/fes-plugin-qiankun/src/main/runtime/MicroApp.tpl @@ -1,6 +1,7 @@ import { defineComponent, ref, + reactive, watch, computed, onBeforeUnmount, @@ -10,21 +11,17 @@ import { loadMicroApp } from "qiankun"; import mergeWith from "lodash/mergeWith"; // eslint-disable-next-line import/extensions import { getMasterOptions } from "./masterOptions"; -{{#HAS_PLUGIN_MODEL}} -import { useModel } from '@@/core/pluginExports'; -{{/HAS_PLUGIN_MODEL}} import { onBeforeRouteLeave } from "@@/core/coreExports"; let unmountPromise; async function unmountMicroApp(microApp) { if (microApp) { - if (microApp.mountPromise) { - await microApp.mountPromise; - } - if (!unmountPromise) { - unmountPromise = microApp.unmount(); - } - return await unmountPromise; + return microApp.mountPromise.then(_microApp => { + // Now it is safe to call unmount + if(_microApp){ + return _microApp.unmount() + } + }) } return Promise.resolve(); } @@ -47,13 +44,7 @@ export const MicroApp = defineComponent({ ...globalSettings } = getMasterOptions(); -{{#HAS_PLUGIN_MODEL}} - // 约定使用 src/models/qiankunStateForMicro 中的数据作为主应用透传给微应用的 props,优先级高于 propsFromConfig - const stateForSlave = useModel('{{{qiankunStateForMicroModelNamespace}}}'); -{{/HAS_PLUGIN_MODEL}} -{{^HAS_PLUGIN_MODEL}} const stateForSlave = reactive({}); -{{/HAS_PLUGIN_MODEL}} // 挂载节点 const containerRef = ref(null); diff --git a/packages/fes-plugin-qiankun/src/main/runtime/getMicroAppRouteComponent.tpl b/packages/fes-plugin-qiankun/src/main/runtime/getMicroAppRouteComponent.tpl index 55b3776b..074ab2cf 100644 --- a/packages/fes-plugin-qiankun/src/main/runtime/getMicroAppRouteComponent.tpl +++ b/packages/fes-plugin-qiankun/src/main/runtime/getMicroAppRouteComponent.tpl @@ -1,11 +1,12 @@ import { MicroApp } from './MicroApp'; export function getMicroAppRouteComponent({ + key, appName, base, masterHistoryType, routeProps }) { - return ; + return ; } diff --git a/packages/fes-plugin-qiankun/src/micro/index.js b/packages/fes-plugin-qiankun/src/micro/index.js index 1945e4f7..2bcd85d2 100644 --- a/packages/fes-plugin-qiankun/src/micro/index.js +++ b/packages/fes-plugin-qiankun/src/micro/index.js @@ -165,7 +165,7 @@ export default function (api) { () => ` export const bootstrap = qiankun_genBootstrap(completeClientRender, app); export const mount = qiankun_genMount('#${api.config.mountElementId}'); -export const unmount = qiankun_genUnmount('#${api.config.mountElementId}'); +export const unmount = qiankun_genUnmount(); export const update = qiankun_genUpdate(); if (!window.__POWERED_BY_QIANKUN__) { diff --git a/packages/fes-plugin-qiankun/src/micro/runtime/lifecycles.tpl b/packages/fes-plugin-qiankun/src/micro/runtime/lifecycles.tpl index 0bebf7c1..b429733c 100644 --- a/packages/fes-plugin-qiankun/src/micro/runtime/lifecycles.tpl +++ b/packages/fes-plugin-qiankun/src/micro/runtime/lifecycles.tpl @@ -46,7 +46,7 @@ export function genBootstrap(oldRender, appPromise) { } // 子应用生命周期钩子Mount -export function genMount() { +export function genMount(mountElementId) { return async (props) => { // props 有值时说明应用是通过 lifecycle 被主应用唤醒的,而不是独立运行时自己 mount if (typeof props !== 'undefined') { @@ -85,17 +85,11 @@ export function genUpdate() { } // 子应用生命周期钩子Unmount -export function genUnmount(mountElementId) { +export function genUnmount() { return async (props) => { - let container; - try { - container = props?.container - ? props.container.querySelector(mountElementId) - : document.querySelector(mountElementId); - } catch (e) {} - if (container && cacheAppPromise) { + if (cacheAppPromise) { const app = await cacheAppPromise; - app.unmount(container); + app.unmount(); } const slaveRuntime = getSlaveRuntime(); if (slaveRuntime.unmount) { diff --git a/packages/fes-preset-built-in/src/plugins/generateFiles/fes/fes.tpl b/packages/fes-preset-built-in/src/plugins/generateFiles/fes/fes.tpl index 927a6382..a586b53a 100644 --- a/packages/fes-preset-built-in/src/plugins/generateFiles/fes/fes.tpl +++ b/packages/fes-preset-built-in/src/plugins/generateFiles/fes/fes.tpl @@ -27,7 +27,7 @@ const renderClient = (opts = {}) => { const app = createApp(rootContainer); app.provide("initialState", initialState); - + plugin.applyPlugins({ key: 'onAppCreated', type: ApplyPluginsType.event, @@ -95,8 +95,5 @@ const completeClientRender = async () => { const app = completeClientRender(); -export default app; - - {{{ entryCode }}} diff --git a/packages/fes-template/.fes.js b/packages/fes-template/.fes.js index 6ffe3d69..430facd6 100644 --- a/packages/fes-template/.fes.js +++ b/packages/fes-template/.fes.js @@ -2,7 +2,10 @@ export default { - base: '', + // base: '', + qiankun: { + micro: {} + }, define: { __DEV__: false }, diff --git a/packages/fes-template/package.json b/packages/fes-template/package.json index 09552223..f9839744 100644 --- a/packages/fes-template/package.json +++ b/packages/fes-template/package.json @@ -55,11 +55,10 @@ "@fesjs/plugin-jest": "^2.0.0-rc.0", "@fesjs/plugin-vuex": "^2.0.0-rc.0", "@fesjs/plugin-request": "^2.0.0-rc.0", - "@fesjs/plugin-qiankun": "^2.0.0-alpha.0", + "@fesjs/plugin-qiankun": "^2.0.0-rc.0", "ant-design-vue": "2.0.0", "vue": "^3.0.5", "vuex": "^4.0.0" }, "private": true } - \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 55736d07..f9fab0c8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6650,7 +6650,7 @@ cross-spawn@^5.0.1: shebang-command "^1.2.0" which "^1.2.9" -cross-spawn@^6.0.0: +cross-spawn@^6.0.0, cross-spawn@^6.0.5: version "6.0.5" resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ== @@ -11610,6 +11610,11 @@ memory-fs@^0.5.0: errno "^0.1.3" readable-stream "^2.0.1" +memorystream@^0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/memorystream/-/memorystream-0.3.1.tgz#86d7090b30ce455d63fbae12dda51a47ddcaf9b2" + integrity sha1-htcJCzDORV1j+64S3aUaR93K+bI= + meow@^3.3.0: version "3.7.0" resolved "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz#72cb668b425228290abbfa856892587308a801fb" @@ -12277,6 +12282,21 @@ npm-pick-manifest@^3.0.0: npm-package-arg "^6.0.0" semver "^5.4.1" +npm-run-all@^4.1.5: + version "4.1.5" + resolved "https://registry.yarnpkg.com/npm-run-all/-/npm-run-all-4.1.5.tgz#04476202a15ee0e2e214080861bff12a51d98fba" + integrity sha512-Oo82gJDAVcaMdi3nuoKFavkIHBRVqQ1qvMb+9LHk/cF4P6B2m8aP04hGf7oL6wZ9BuGwX1onlLhpuoofSyoQDQ== + dependencies: + ansi-styles "^3.2.1" + chalk "^2.4.1" + cross-spawn "^6.0.5" + memorystream "^0.3.1" + minimatch "^3.0.4" + pidtree "^0.3.0" + read-pkg "^3.0.0" + shell-quote "^1.6.1" + string.prototype.padend "^3.0.0" + npm-run-path@^2.0.0: version "2.0.2" resolved "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f" @@ -12944,6 +12964,11 @@ picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.2.1, picomatch@^2.2.2: resolved "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad" integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg== +pidtree@^0.3.0: + version "0.3.1" + resolved "https://registry.yarnpkg.com/pidtree/-/pidtree-0.3.1.tgz#ef09ac2cc0533df1f3250ccf2c4d366b0d12114a" + integrity sha512-qQbW94hLHEqCg7nhby4yRC7G2+jYHY4Rguc2bjw7Uug4GIJuu1tvf2uHaZv5Q8zdt+WKJ6qK1FOI6amaWUo5FA== + pify@^2.0.0, pify@^2.3.0: version "2.3.0" resolved "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c" @@ -14777,6 +14802,11 @@ shebang-regex@^3.0.0: resolved "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== +shell-quote@^1.6.1: + version "1.7.2" + resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.2.tgz#67a7d02c76c9da24f99d20808fcaded0e0e04be2" + integrity sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg== + shellwords@^0.1.1: version "0.1.1" resolved "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" @@ -15229,6 +15259,15 @@ string-width@^4.1.0, string-width@^4.2.0: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.0" +string.prototype.padend@^3.0.0: + version "3.1.2" + resolved "https://registry.yarnpkg.com/string.prototype.padend/-/string.prototype.padend-3.1.2.tgz#6858ca4f35c5268ebd5e8615e1327d55f59ee311" + integrity sha512-/AQFLdYvePENU3W5rgurfWSMU6n+Ww8n/3cUt7E+vPBB/D7YDG8x+qjoFs4M/alR2bW7Qg6xMjVwWUOvuQ0XpQ== + dependencies: + call-bind "^1.0.2" + define-properties "^1.1.3" + es-abstract "^1.18.0-next.2" + string.prototype.trimend@^1.0.4: version "1.0.4" resolved "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.4.tgz#e75ae90c2942c63504686c18b287b4a0b1a45f80"