We are trying microfrontends with ModuleFederationPlugin
from Webpack 5.61.0 .
I feel so helpless.
I'm using @vue/[email protected]
.
The vue.config.js
which exposes its modules looks like below,
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const { defineConfig } = require('@vue/cli-service');
module.exports = defineConfig({
publicPath: "http://localhost:8080/",
configureWebpack: {
plugins: [
new ModuleFederationPlugin({
name: "items",
filename: "remoteEntry.js",
exposes: {
"./ItemsBase": "./src/components/ItemsBase.vue"
},
shared: require("./package.json").dependencies
})
]
},
transpileDependencies: [
'vuetify'
]
})
And the consumer's vue.config.js
looks like this,
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const { defineConfig } = require('@vue/cli-service');
module.exports = defineConfig({
publicPath: "http://localhost:8081/",
configureWebpack: {
plugins: [
new ModuleFederationPlugin({
name: "my_shop",
filename: "remoteEntry.js",
remotes: {
"items": "items@http://localhost:8080/remoteEntry.js"
},
shared: require("./package.json").dependencies
})
]
},
transpileDependencies: [
'vuetify'
]
})
I have the bootstrap.js
in both projects an I'm importing it like import('./bootstrap')
from main.js
On the consumer project we are trying to import the remote component like this.
<template>
<div >
<ItemsBase></ItemsBase>
</div>
</template>
<script>
// @ is an alias to /src
export default {
name: 'HomeView',
components: {
ItemsBase: () => import("items/ItemsBase")
}
}
</script>
And this mix is based on webpack examples with vue-cli: https://github.com/module-federation/module-federation-examples/tree/master/vue-cli
The only difference is that they are using [email protected]
but both have same webpack version(my prototypes and webpack samples).
Now the interesting part is that I'm getting the following error in the consumer project.
ScriptExternalLoadError: Loading script failed
any ideas?
Edit: Another difference is that the vue-cli sample from webpack is using yarn and I'm using npm which is just irrelevant but thought maybe it worths mentioning because their example works!!!
CodePudding user response:
Well I found out why this is happening. I opened an issue in github on vue-cli. https://github.com/vuejs/vue-cli/issues/6823
On Saturday(06.11) the [email protected] release on npm and well with npm I could not again create a new vue app for any of the vue-cli versions. because it adds the version 5.0.0 of each packages in package.json and apparently they don't exist in npm but it works with yarn.
I could not get the module federation to work with [email protected]
but as used in the webpack example for vue-cli I could get it to work with [email protected]
.