From a03a2e68df6a677efc85e8d8861106ad73d815e1 Mon Sep 17 00:00:00 2001 From: zhangHongEn Date: Tue, 12 Dec 2023 16:54:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0baseUrl=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mf-example/app1/package.json | 2 +- packages/mf-example/app1/src/App.js | 4 ++-- packages/mf-example/app1/webpack.config.js | 17 +++++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/mf-example/app1/package.json b/packages/mf-example/app1/package.json index ffb33e9..78e887d 100644 --- a/packages/mf-example/app1/package.json +++ b/packages/mf-example/app1/package.json @@ -24,7 +24,7 @@ "@babel/preset-react": "^7.13.13", "babel-loader": "^8.2.2", "html-webpack-plugin": "^5.3.1", - "npm-federation": "^1.0.9", + "npm-federation": "^1.0.11", "webpack": "^5.38.1", "webpack-cli": "^4.7.2", "webpack-dev-server": "^4.0.0", diff --git a/packages/mf-example/app1/src/App.js b/packages/mf-example/app1/src/App.js index dfbe8c8..03cd7ba 100644 --- a/packages/mf-example/app1/src/App.js +++ b/packages/mf-example/app1/src/App.js @@ -1,7 +1,7 @@ -import * as reactRouter from "react-router" +import * as reactRouter from "@remix-run/router" import React from "react"; import ReactDom from "react-dom"; -console.log("react-router", reactRouter) +console.log("remix-router", reactRouter) const App = () => { return ( diff --git a/packages/mf-example/app1/webpack.config.js b/packages/mf-example/app1/webpack.config.js index 088cda5..51ab8c6 100644 --- a/packages/mf-example/app1/webpack.config.js +++ b/packages/mf-example/app1/webpack.config.js @@ -35,7 +35,6 @@ module.exports = { plugins: [ // To learn more about the usage of this plugin, please visit https://webpack.js.org/plugins/module-federation-plugin/ new NpmFederation({ - // Inject some code through initial (not required) initial: ` console.log("Inject code wpmjsInstance", wpmjs) wpmjs.sleep(new Promise(resolve => { @@ -43,6 +42,9 @@ module.exports = { const json = { "@remix-run/router": { packageVersion: "1.9.0" + }, + "mf-app-02": { + packageVersion: "1.0.6" } } setTimeout(() => { @@ -50,15 +52,14 @@ module.exports = { wpmjs.addImportMap(json) resolve() }, 100) - })) - `, - config: { - baseUrl: "https://cdn.jsdelivr.net/npm" - }, + }))`, + baseUrl: "https://cdn.jsdelivr.net/npm", remotes: { "@remix-run/router": "@remix-run/router/dist/router.umd.min.js", - "react-router": "react-router@latest/dist/umd/react-router.development.js", - "mf-app-02": "mfapp02@https://cdn.jsdelivr.net/npm/mf-app-02/dist/remoteEntry.js" + "mf-app-02": { + package: "mf-app-02/dist/remoteEntry.js", + global: "mfapp02" + }, }, name: 'mfapp01', filename: 'remoteEntry.js',