Code Monkey home page Code Monkey logo

coexisting-vue-microfrontends's Introduction

Try the newer example repo

The newer example demonstrating Vue Microfrontends can be found at https://github.com/vue-microfrontends and https://vue.microfrontends.app. That example better reflects the microfrontends architecture and is encouraged to use.

Coexisting Vue Microfrontends

Build Status

Demo: http://coexisting-vue-microfrontends.surge.sh

This is a starter-kit / example repository for people who want to have multiple vue microfrontends coexist within a single page. Each of the vue applications was created by Vue CLI.

It uses single-spa to pull this off, which means that you can even add React, Angular, or other frameworks as additional microfrontends.

An important note

This github repository has four projects all in one repo. But when you do this yourself, you'll want to have one git repo per vue application. The root-html-file project should also be in its own repo. This is what lets different teams and developers be in charge of different microfrontends.

Local development -- one app at a time

Tutorial video

With single-spa, it is preferred to run npm run serve in only one single-spa application at a time, while using a deployed version of the other applications. This makes for an awesome developer experience where you can boot up just one microfrontend at a time, not even having to clone, npm install, or boot up all of the other ones.

To try this out, clone the repo and run the following commands:

cd app1
npm i
npm run serve

Now go to http://coexisting-vue-microfrontends.surge.sh in a browser. In a browser console, run localStorage.setItem('overrides-ui', true). Refresh the page. Now click on the yellowish rectangle at the bottom right. Then click on app1. Change the module url to http://localhost:8081/js/app.js. Then apply the override and reload the page. This will have change app1 to load from your localhost instead of from surge.sh. As you modify the code locally, it will reload the page on coexisting-vue-microfrontends.surge.sh. See https://github.com/joeldenning/import-map-overrides for more info on this.

Local development -- all at once

It is preferred to only run one app at a time. But if you need to run them all locally, you can do so with the following instructions

# First terminal tab
cd root-html-file
npm install
npm run serve
# Second terminal tab
cd app1
npm install
npm run serve
# Third terminal tab
cd app2
npm install
npm run serve
# Fourth terminal tab
cd navbar
npm install
npm run serve

Now go to http://localhost:5000 in a browser. Note that you can change any of the ports for the projects by modifying the Import Map inside of root-html-file/index.html.

If you get serious about deploying your code, you'll want to make it no longer necessary to boot up all of the apps in order to do anything. When you get to that point, check out import-map-overrides, which lets you go to a deployed environment and override the Import Map for just one microfrontend at a time. The import-map-overrides library is already loaded in the index.html of root-html-file, so you can start using it immediately. You can make your deployed environment overridable, just like you can do overrides on http://coexisting-vue-microfrontends.surge.sh

More documentation

Go to https://single-spa.js.org/docs/ecosystem-vue.html to learn how all of this works.

coexisting-vue-microfrontends's People

Contributors

52admln avatar dependabot[bot] avatar evanburbidge avatar joeldenning avatar kuwv avatar mario-huang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coexisting-vue-microfrontends's Issues

vue 3 and vue-router 4

hi
could you create an example of import map with vue 3 and vue-router 4 please?
thanks

Standalone Mode

Is there a way to run subapps independently, via some scripts in package.json?

How can I import components?

How can I import a component?
I'm trying to do that but always throw this anoying error:

Module not found: Error: Can't resolve '/components/home.vue' in 'D:\estudos\microfrontend\single-spa-app\src\vue'
 @ ./src/vue/main.vue?vue&type=script&lang=js& (./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./src/vue/main.vue?vue&type=script&lang=js&) 4:0-40 7:10-14
 @ ./src/vue/main.vue?vue&type=script&lang=js&
 @ ./src/vue/main.vue
 @ ./src/vue/vue.app.js
 @ ./single-spa.config.js

If you could help me this is my repo.

跨域了,这么办呢

(index):1 Access to script at 'http://localhost:8080/js/app.js' from origin 'http://localhost:5000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
system.min.js:4 GET http://localhost:8080/js/app.js net::ERR_FAILED
(anonymous) @ system.min.js:4
g.instantiate @ system.min.js:4
t.instantiate @ system.min.js:4
t.instantiate @ named-register.min.js:1
(anonymous) @ system.min.js:4
Promise.then (async)
t @ system.min.js:4
(anonymous) @ system.min.js:4
Promise.then (async)
g.import @ system.min.js:4
e.import @ system.min.js:4
t.import @ use-default.min.js:1
(anonymous) @ (index):42
(anonymous) @ single-spa.min.js:1
Promise.then (async)
(anonymous) @ single-spa.min.js:1
Promise.then (async)
tt @ single-spa.min.js:1
(anonymous) @ single-spa.min.js:1
Promise.then (async)
Ct @ single-spa.min.js:1
Tt @ single-spa.min.js:1
(anonymous) @ (index):40
Promise.then (async)
(anonymous) @ (index):33
(anonymous) @ (index):60
single-spa.min.js:1 Uncaught navbar: Application 'navbar' died in status LOADING_SOURCE_CODE: Error loading http://localhost:8080/js/app.js
at HTMLScriptElement. (https://cdnjs.cloudflare.com/ajax/libs/systemjs/6.1.1/system.min.js:4:5825)

Images from the individual applications doesnt appear

Hi,
When the individual app is invoked the logo/images from that module doesnt load it gives error as it takes the parent path for search and loading.

The same is seen in the sample app as well.

Can you please guide on this.

Thanks

Picture not found

I'm now under the navbar project, I'm going to put an image and I'm going to reference it on the page, and then I'm going to run project 5000, and it's going to show me the image's load path is 5000 and I can't find that image. How do you solve this?

why do this in 'root-html-file/index.html'

What error did you get?

i hava a similar doubt

when i commented out this code in ‘root-html-file/index.html’

// 'root-html-file/index.html'

Promise.all([System.import('single-spa'), System.import('vue'), System.import('vue-router')]).then(function (modules) {   
    //var singleSpa = modules[0];
    //var Vue = modules[1];
    //var VueRouter = modules[2];
    //Vue.use(VueRouter)

it will be error to use router in 'navbar/src/App.vue'

this.$router.push('/navbar')
// this.$router   is  undefined

image

but it works in vue-microfrontends[https://github.com/vue-microfrontends]

Originally posted by @mango-csl in #37 (comment)

Isolated styles

Hi, I have same style class name like '.app' in app1 and app2.
But there are not Isolated, any ideas?

'app-name' died in status LOADING_SOURCE_CODE: "does not export an unmount function or array of functions"

When dynamically loading vue cli app using import statement
singleSpa.registerApplication(' app-3', () => import (/* webpackIgnore: true */'http://localhost:8080/app.js'), pathPrefix('/app3'));

causes following exception:
Uncaught Error: 'app-3' died in status LOADING_SOURCE_CODE: "does not export an unmount function or array of functions"

My sample vue main.js file looks like this:
`import Vue from vue
import App from './App.vue'
import singleSpaVue from 'single-spa-vue';
Vue.config.productionTip = true
const vueLifecycles = singleSpaVue({
Vue,
appOptions: {
render: (h) => h(App)
},
});

export const bootstrap = vueLifecycles.bootstrap;
export const mount = vueLifecycles.mount;
export const unmount = vueLifecycles.unmount;
`

Support for IE 11.

Can we expect support for IE11 for coexisting-vue-microfrontend app ?

vuex

Is it okay to use vuex in a project by referring to vue-router?
Is there anything to pay attention to?

create a new div element with each click

Hi,

When I review the application demo.
each time app1 or app2 is clicked, it creates a new div element.

< div id="app1" >< /div >
< div id="app2" >< /div >
< div id="app1" >< /div >
< div id="app2" >< /div >
....

vue-cli3

Sorry to trouble you again. I have two problem.

  1. I use vue-cli3 to make a project, modify according to app1, but error
    image
  2. I have deploy the app1 and app2 in the 3001 server, then click app1, make a error
    image
    Only if I refresh my browser, the picture will appear.

Vuex can't work??

app-errors.js:9 Uncaught main: Application 'main' died in status LOADING_SOURCE_CODE: t.isBuffer is not a function
    at y (<anonymous>:1:2232)
    at f (<anonymous>:1:3275)
    at Object.<anonymous> (<anonymous>:1:928)
    at Object.r (<anonymous>:1:375)
    at Object.emit (<anonymous>:1:694)
    at devtoolPlugin (http://localhost:8080/app.js:12740:15)
    at new Store (http://localhost:8080/app.js:13042:5)
    at Module../src/store.js (http://localhost:8080/app.js:15034:64)
    at __webpack_require__ (http://localhost:8080/app.js:737:30)
    at fn (http://localhost:8080/app.js:111:20)
import "./set-public-path";
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import singleSpaVue from "single-spa-vue";
import store from "./store";
Vue.config.productionTip = false;

const vueLifecycles = singleSpaVue({
    Vue,
    appOptions: {
        render: h => h(App),
        router,
        store
    }
});

export const bootstrap = vueLifecycles.bootstrap;
export const mount = vueLifecycles.mount;
export const unmount = vueLifecycles.unmount;

If port 8080 is not free before start serve microApp, it occurs error

Error

app-errors.js:9 Uncaught navbar: Application 'navbar' died in status LOADING_SOURCE_CODE: Error loading http://localhost:8080/app.js
    at HTMLScriptElement.<anonymous> (https://cdnjs.cloudflare.com/ajax/libs/systemjs/6.1.1/system.min.js:4:5825)

Expected

If port 8080 is dominant before start app1, app2, navbar, these port will be automatically use incremental port(that is ok), but shoud not occurs error.

how to build and deploy?

could you tell me how to build this project and how to deploy it in production environment ?
thanks a lot , and waiting for you reply.

Application died in status LOADING_SOURCE_CODE: window.Vue.use is not a function

singleSpa.registerApplication(
'proj1',
() => System.import('proj1'),
location => location.hash.startsWith('#/jpro')
// location => true
)

when I use: location => location.hash.startsWith('#/jpro') , I get the error below,but it works fine when I use: location => true; I don't konw why? please help me. thanks a lot

Uncaught proj1: Application 'proj1' died in status LOADING_SOURCE_CODE: window.Vue.use is not a function
at Module../node_modules/vue-router/dist/vue-router.esm.js (http://localhost:8002/app.js:261976:14)
at webpack_require (http://localhost:8002/app.js:778:30)
at fn (http://localhost:8002/app.js:141:20)
at Module../src/router/index.js (http://localhost:8002/app.js:283598:68)
at webpack_require (http://localhost:8002/app.js:778:30)
at fn (http://localhost:8002/app.js:141:20)
at Module../src/main.js (http://localhost:8002/app.js:281169:67)
at webpack_require (http://localhost:8002/app.js:778:30)
at fn (http://localhost:8002/app.js:141:20)
at Object.2 (http://localhost:8002/app.js:284653:18)

Unexpected token '<'

npm run build
production: use nginx
When the page is refreshed, Error occurred
image

Coexisting vue2 and vue3

Is it posible to coexist vue2 and vue3? This would be usefull to migrage progressively one application.

The superposition of CSS and JS

When I switched apps, the CSS and JS of other apps that used to be active remained in the head.

I think we should remove the CSS and JS of other apps and keep only the current active's

error3
Multiple Vue instances in the same document need to avoid global variable pollution, global monitoring pollution, style pollution and so on. Access specifications need to be formulated.

component: () => import( /* webpackChunkName: "about" */ './views/About.vue')

Hello,I built the app3 project with reference to APP2, but in both projects, when I clicked route about, an error occurred.
error

Because when you switch app2 or app3, the URL address of about.js does not change, but when you refresh it, it becomes the correct address.

Accessing a large subapp, I found that the problem caused by lazy routing loading prevented the handover from successfully switching to other apps.
If you don't use routing lazy loading, there's no problem.

Upgrade to vue cli 4

We should update this example to vue cli 4. I would love to accept a PR for this.

Question: New Example Repo

You mention that the newer example repo better reflects the micro frontend architecture and is encouraged to use.

Can you explain the primary architectural differences between this example and the newer example? What are some of the biggest or most significant changes?

Thank you

RangeError: Maximum call stack size exceeded

I use single-spa, and single-spa-vue to integrate some vue(vue cli3) projects. When I operate the integrated pages, the following error has occurred. Can you tell me the possible reasons? I look forward to your reply.

Uncaught (in promise) RangeError: Maximum call stack size exceeded
at RegExp.exec ()
at RegExp.[Symbol.match] ()
at String.match ()
at _t (app.js:42)
at s (app.js:42)
at c (app.js:42)
at u (app.js:42)
at s (app.js:42)
at c (app.js:42)
at u (app.js:42)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.