Skip to content

Commit

Permalink
feat(vue): introduce vue component binding (#2775)
Browse files Browse the repository at this point in the history
  • Loading branch information
linghaoSu authored Dec 5, 2023
1 parent 2e528c9 commit fdb5f8a
Show file tree
Hide file tree
Showing 24 changed files with 4,043 additions and 2,268 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const tsConfig = {
extends: ['plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/recommended-requiring-type-checking'],
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.eslint.json', './packages/*/tsconfig.json'],
project: ['./tsconfig.eslint.json', './packages/**/tsconfig.json'],
},
rules: {
'@typescript-eslint/no-unnecessary-condition': 'error',
Expand Down
12 changes: 10 additions & 2 deletions examples/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"main": "index.js",
"scripts": {
"start": "webpack-dev-server",
"start:vue": "cross-env MODE=vue webpack-dev-server",
"start:vue3": "cross-env MODE=vue3 webpack-dev-server",
"start:multiple": "cross-env MODE=multiple webpack-dev-server",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand All @@ -27,8 +29,14 @@
"qiankun": "^2.10.10",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"vue": "^2.6.11",
"zone.js": "^0.10.2"
"vue": "^3.3.9",
"zone.js": "^0.10.2",
"@vue/composition-api": "1.7.2"
},
"peerDependenciesMeta": {
"@vue/composition-api": {
"optional": true
}
},
"repository": "[email protected]:umijs/qiankun.git"
}
32 changes: 32 additions & 0 deletions examples/main/render/VanillaRender.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { loadMicroApp } from '../../../packages/qiankun/dist/esm';
// import { loadMicroApp } from 'qiankun';
import '../index.less';

const microApps = [
{ name: 'react15', entry: '//localhost:7102' },
{ name: 'react16', entry: '//localhost:7100' },
];

let prevApp;
let prevAppName;
document.querySelector('.mainapp-sidemenu').addEventListener('click', async (e) => {
window.startTime = Date.now();
const app = microApps.find((app) => app.name === e.target.dataset.value);
if (app) {
if (app.name === prevAppName) return;

await prevApp?.unmount();

prevApp = loadMicroApp(
{
name: app.name,
entry: app.entry,
container: document.querySelector('#subapp-container'),
},
{ sandbox: true },
);
prevAppName = app.name;
} else {
console.log('not found any app');
}
});
44 changes: 44 additions & 0 deletions examples/main/render/Vue3Render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { createApp, h } from 'vue';
import { MicroApp } from '../../../packages/ui-bindings/vue/dist/esm';


function vueRender() {
const application = createApp({
components: {
},
render() {
return h('div', [
this.message,
h(MicroApp, { name: 'react15', entry: '//localhost:7102' }),
this.message,
]);
},
setup() {
const message = 'abc';

return {
message,
};
// return () => h('div', [
// message.value,
// h(MicroApp, { name: 'react15', entry: '//localhost:7102' }),
// message.value,
// ]);
}
});

application.mount('#subapp-container');

return application;
}

let app = null;

function render() {
if (!app) {
app = vueRender();
console.log(app)
}
}

render();
44 changes: 30 additions & 14 deletions examples/main/render/VueRender.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
import Vue from 'vue/dist/vue.esm';
import Vue from 'vue/dist/vue.esm.js';
import compositionApi from '@vue/composition-api';
import { MicroApp } from '../../../packages/ui-bindings/vue/dist/esm/';

function vueRender({ loading }) {
Vue.use(compositionApi);
// Vue.component('MicroApp', MicroApp)
function vueRender() {
return new Vue({
components: {
MicroApp,
},
data: {
message: 'abc',
},
name: 'vueRender',
template: `
<div id="subapp-container">
<h4 v-if="loading" class="subapp-loading">Loading...</h4>
<div id="subapp-viewport"></div>
<div>
<MicroApp name="react15" entry="//localhost:7102" />
</div>
`,
// render(h) {
// return h('div', [
// h(MicroApp, {
// props: {
// name: 'react15',
// entry: '//localhost:7102',
// }
// }),
// ]);
// },
el: '#subapp-container',
data() {
return {
loading,
};
},
});
}

let app = null;

export default function render({ loading }) {
function render() {
if (!app) {
app = vueRender({ loading });
} else {
app.loading = loading;
app = vueRender();
console.log(app)
}
}

render();
23 changes: 21 additions & 2 deletions examples/main/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { name } = require('./package');
const path = require('path');

const modeEntryMap = {
multiple: './multiple.js',
vue: './render/VueRender.js',
vue3: './render/Vue3Render.js',
undefined: './render/VanillaRender.js',
}

const modeHTMLMap = {
multiple: './multiple.html',
vue: './index.html',
vue3: './index.html',
undefined: './index.html',
}

module.exports = {
entry: process.env.MODE === 'multiple' ? './multiple.js' : './index.js',
entry: modeEntryMap[process.env.MODE],
devtool: 'source-map',
devServer: {
open: true,
Expand All @@ -22,6 +37,10 @@ module.exports = {
mode: 'development',
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
alias: {
vue: path.join(__dirname, 'node_modules/vue')
// '@vue/composition-api': path.join(__dirname, 'node_modules/@vue/composition-api')
}
},
module: {
rules: [
Expand All @@ -45,7 +64,7 @@ module.exports = {
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: process.env.MODE === 'multiple' ? './multiple.html' : './index.html',
template: modeHTMLMap[process.env.MODE],
minify: {
removeComments: true,
collapseWhitespace: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/qiankun/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { version } from '../package.json';
export const version = '3.0.0-rc.11';
Loading

0 comments on commit fdb5f8a

Please sign in to comment.