{"id":299,"date":"2026-10-29T11:27:54","date_gmt":"2026-10-29T03:27:54","guid":{"rendered":"https:\/\/yykcj.com\/?p=299"},"modified":"2026-10-29T11:27:54","modified_gmt":"2026-10-29T03:27:54","slug":"%e5%89%8d%e7%ab%af%e5%be%ae%e6%9c%8d%e5%8a%a1%e6%9e%b6%e6%9e%84%e5%ae%9e%e8%b7%b5%ef%bc%9a%e5%9f%ba%e4%ba%8e-module-federation-%e7%9a%84%e5%be%ae%e5%89%8d%e7%ab%af%e8%90%bd%e5%9c%b0%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/yykcj.com\/?p=299","title":{"rendered":"\u524d\u7aef\u5fae\u670d\u52a1\u67b6\u6784\u5b9e\u8df5\uff1a\u57fa\u4e8e Module Federation \u7684\u5fae\u524d\u7aef\u843d\u5730\u6307\u5357"},"content":{"rendered":"<h2>\u4e3a\u4ec0\u4e48\u9700\u8981\u524d\u7aef\u5fae\u670d\u52a1\uff1f<\/h2>\n<p>\u968f\u7740\u4e1a\u52a1\u89c4\u6a21\u6269\u5927\uff0c\u5355\u4f53\u524d\u7aef\u5e94\u7528\u9010\u6e10\u66b4\u9732\u51fa\u4ee5\u4e0b\u95ee\u9898\uff1a<\/p>\n<ul>\n<li><strong>\u6784\u5efa\u901f\u5ea6\u6162<\/strong>\uff1a\u4ee3\u7801\u5e93\u5e9e\u5927\uff0c\u6bcf\u6b21\u6784\u5efa\u8017\u65f6\u6570\u5206\u949f\u751a\u81f3\u66f4\u4e45\u3002<\/li>\n<li><strong>\u56e2\u961f\u534f\u4f5c\u51b2\u7a81<\/strong>\uff1a\u591a\u4e2a\u56e2\u961f\u4fee\u6539\u540c\u4e00\u4ed3\u5e93\uff0c\u4ee3\u7801\u5408\u5e76\u51b2\u7a81\u9891\u7e41\u3002<\/li>\n<li><strong>\u6280\u672f\u6808\u9501\u5b9a<\/strong>\uff1a\u96be\u4ee5\u6e10\u8fdb\u5f0f\u5347\u7ea7\u6846\u67b6\u6216\u5e93\u3002<\/li>\n<li><strong>\u90e8\u7f72\u8026\u5408<\/strong>\uff1a\u4efb\u4f55\u5c0f\u6539\u52a8\u90fd\u9700\u8981\u5168\u91cf\u53d1\u5e03\uff0c\u98ce\u9669\u9ad8\u3002<\/li>\n<\/ul>\n<p>\u5fae\u524d\u7aef\uff08Micro Frontends\uff09\u501f\u9274\u4e86\u540e\u7aef\u5fae\u670d\u52a1\u7684\u601d\u60f3\uff0c\u5c06\u524d\u7aef\u5e94\u7528\u62c6\u5206\u4e3a\u591a\u4e2a\u53ef\u72ec\u7acb\u5f00\u53d1\u3001\u6d4b\u8bd5\u548c\u90e8\u7f72\u7684\u5b50\u5e94\u7528\uff0c\u518d\u901a\u8fc7\u4e00\u4e2a\u5bb9\u5668\u5e94\u7528\u96c6\u6210\u3002\u800c Webpack 5 \u7684 <strong>Module Federation<\/strong> \u8ba9\u8fd9\u4e00\u67b6\u6784\u7684\u5b9e\u73b0\u53d8\u5f97\u524d\u6240\u672a\u6709\u7684\u7b80\u5355\u3002<\/p>\n<p>\u672c\u6587\u5c06\u5e26\u4f60\u4ece\u96f6\u642d\u5efa\u4e00\u4e2a\u57fa\u4e8e Module Federation \u7684\u5fae\u524d\u7aef\u7cfb\u7edf\uff0c\u5305\u542b\u5bb9\u5668\u5e94\u7528\uff08Host\uff09\u548c\u4e24\u4e2a\u8fdc\u7a0b\u5e94\u7528\uff08Remote\uff09\uff0c\u5e76\u89e3\u51b3\u6837\u5f0f\u9694\u79bb\u3001\u901a\u4fe1\u3001\u8def\u7531\u7b49\u6838\u5fc3\u95ee\u9898\u3002<\/p>\n<h2>\u67b6\u6784\u8bbe\u8ba1<\/h2>\n<p>\u6211\u4eec\u8bbe\u8ba1\u4e00\u4e2a\u7535\u5546\u540e\u53f0\u7ba1\u7406\u7cfb\u7edf\uff0c\u62c6\u5206\u4e3a\u4e09\u4e2a\u72ec\u7acb\u5e94\u7528\uff1a<\/p>\n<ul>\n<li><strong>host<\/strong>\uff1a\u5bb9\u5668\u5e94\u7528\uff0c\u8d1f\u8d23\u5e03\u5c40\u3001\u8def\u7531\u548c\u96c6\u6210\u5b50\u5e94\u7528\u3002<\/li>\n<li><strong>products<\/strong>\uff1a\u5546\u54c1\u7ba1\u7406\u5b50\u5e94\u7528\uff08React\uff09\u3002<\/li>\n<li><strong>orders<\/strong>\uff1a\u8ba2\u5355\u7ba1\u7406\u5b50\u5e94\u7528\uff08Vue 3\uff09\u3002<\/li>\n<\/ul>\n<p>\u5b50\u5e94\u7528\u53ef\u4ee5\u72ec\u7acb\u5f00\u53d1\u8fd0\u884c\uff0c\u4e5f\u53ef\u4ee5\u88ab\u5bb9\u5668\u96c6\u6210\u3002\u6280\u672f\u6808\u4e0d\u540c\uff0c\u4f46\u901a\u8fc7 Module Federation \u5171\u4eab\u4f9d\u8d56\u548c\u7ec4\u4ef6\u3002<\/p>\n<h2>\u73af\u5883\u51c6\u5907<\/h2>\n<p>\u786e\u4fdd Node.js \u2265 14\uff0c\u5e76\u5b89\u88c5 pnpm\uff08\u6216 npm\/yarn\uff09\u3002<\/p>\n<pre><code class=\"language-bash\">\nmkdir micro-frontend-demo &amp;&amp; cd micro-frontend-demo\npnpm init\n<\/code><\/pre>\n<p>\u521b\u5efa\u4e09\u4e2a\u5b50\u76ee\u5f55\uff1a<code>host<\/code>\u3001<code>products<\/code>\u3001<code>orders<\/code>\uff0c\u5206\u522b\u521d\u59cb\u5316\u3002<\/p>\n<pre><code class=\"language-bash\">\nmkdir host products orders\ncd host &amp;&amp; pnpm create vite@latest . --template react\ncd ..\/products &amp;&amp; pnpm create vite@latest . --template react\ncd ..\/orders &amp;&amp; pnpm create vite@latest . --template vue\n<\/code><\/pre>\n<p>\u4e3a\u7b80\u5316\uff0c\u6211\u4eec\u4f7f\u7528 Vite \u521b\u5efa\u9879\u76ee\uff0c\u4f46 Module Federation \u9700\u8981 Webpack 5\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u5c06 Vite \u9879\u76ee\u8fc1\u79fb\u5230 Webpack 5\u3002\u6216\u8005\u76f4\u63a5\u4f7f\u7528 Webpack \u521d\u59cb\u5316\u3002\u8fd9\u91cc\u4e3a\u4e86\u805a\u7126 Module Federation\uff0c\u6211\u4eec\u624b\u52a8\u914d\u7f6e Webpack\u3002<\/p>\n<h3>\u5b89\u88c5 Webpack \u76f8\u5173\u4f9d\u8d56<\/h3>\n<p>\u5728\u6bcf\u4e2a\u9879\u76ee\u4e2d\u5b89\u88c5\uff1a<\/p>\n<pre><code class=\"language-bash\">\npnpm add -D webpack webpack-cli webpack-dev-server html-webpack-plugin babel-loader @babel\/core @babel\/preset-env @babel\/preset-react\n<\/code><\/pre>\n<p>\u5bf9\u4e8e Vue \u9879\u76ee\uff0c\u8fd8\u9700\u8981 <code>vue-loader<\/code> \u548c <code>@vue\/compiler-sfc<\/code>\u3002<\/p>\n<h2>\u914d\u7f6e Module Federation<\/h2>\n<h3>1. \u5bb9\u5668\u5e94\u7528\uff08host\uff09<\/h3>\n<p>\u5728 <code>host<\/code> \u76ee\u5f55\u521b\u5efa <code>webpack.config.js<\/code>\uff1a<\/p>\n<pre><code class=\"language-javascript\">\nconst HtmlWebpackPlugin = require(&#x27;html-webpack-plugin&#x27;);\nconst { ModuleFederationPlugin } = require(&#x27;webpack&#x27;).container;\nconst deps = require(&#x27;.\/package.json&#x27;).dependencies;\n\nmodule.exports = {\n  entry: &#x27;.\/src\/index.js&#x27;,\n  mode: &#x27;development&#x27;,\n  devServer: {\n    port: 3000,\n    historyApiFallback: true,\n  },\n  output: {\n    publicPath: &#x27;auto&#x27;,\n  },\n  module: {\n    rules: [\n      {\n        test: \/\\.jsx?$\/,\n        exclude: \/node_modules\/,\n        use: {\n          loader: &#x27;babel-loader&#x27;,\n          options: {\n            presets: [&#x27;@babel\/preset-env&#x27;, &#x27;@babel\/preset-react&#x27;],\n          },\n        },\n      },\n    ],\n  },\n  plugins: [\n    new ModuleFederationPlugin({\n      name: &#x27;host&#x27;,\n      remotes: {\n        products: &#x27;products@http:\/\/localhost:3001\/remoteEntry.js&#x27;,\n        orders: &#x27;orders@http:\/\/localhost:3002\/remoteEntry.js&#x27;,\n      },\n      shared: {\n        react: { singleton: true, requiredVersion: deps.react },\n        &#x27;react-dom&#x27;: { singleton: true, requiredVersion: deps[&#x27;react-dom&#x27;] },\n      },\n    }),\n    new HtmlWebpackPlugin({\n      template: &#x27;.\/public\/index.html&#x27;,\n    }),\n  ],\n};\n<\/code><\/pre>\n<p>\u5173\u952e\u70b9\uff1a<\/p>\n<ul>\n<li><code>remotes<\/code> \u58f0\u660e\u8fdc\u7a0b\u5e94\u7528\u7684\u540d\u79f0\u548c\u5165\u53e3\u6587\u4ef6\u5730\u5740\u3002<\/li>\n<li><code>shared<\/code> \u6307\u5b9a\u5171\u4eab\u4f9d\u8d56\uff0c<code>singleton: true<\/code> \u786e\u4fdd\u53ea\u52a0\u8f7d\u4e00\u4e2a React \u5b9e\u4f8b\uff0c\u907f\u514d\u51b2\u7a81\u3002<\/li>\n<\/ul>\n<h3>2. \u5546\u54c1\u5b50\u5e94\u7528\uff08products\uff09<\/h3>\n<p>\u5728 <code>products<\/code> \u76ee\u5f55\u521b\u5efa <code>webpack.config.js<\/code>\uff1a<\/p>\n<pre><code class=\"language-javascript\">\nconst HtmlWebpackPlugin = require(&#x27;html-webpack-plugin&#x27;);\nconst { ModuleFederationPlugin } = require(&#x27;webpack&#x27;).container;\nconst deps = require(&#x27;.\/package.json&#x27;).dependencies;\n\nmodule.exports = {\n  entry: &#x27;.\/src\/index.js&#x27;,\n  mode: &#x27;development&#x27;,\n  devServer: {\n    port: 3001,\n    historyApiFallback: true,\n  },\n  output: {\n    publicPath: &#x27;auto&#x27;,\n  },\n  module: {\n    rules: [\n      {\n        test: \/\\.jsx?$\/,\n        exclude: \/node_modules\/,\n        use: {\n          loader: &#x27;babel-loader&#x27;,\n          options: {\n            presets: [&#x27;@babel\/preset-env&#x27;, &#x27;@babel\/preset-react&#x27;],\n          },\n        },\n      },\n    ],\n  },\n  plugins: [\n    new ModuleFederationPlugin({\n      name: &#x27;products&#x27;,\n      filename: &#x27;remoteEntry.js&#x27;,\n      exposes: {\n        &#x27;.\/ProductList&#x27;: &#x27;.\/src\/components\/ProductList&#x27;,\n      },\n      shared: {\n        react: { singleton: true, requiredVersion: deps.react },\n        &#x27;react-dom&#x27;: { singleton: true, requiredVersion: deps[&#x27;react-dom&#x27;] },\n      },\n    }),\n    new HtmlWebpackPlugin({\n      template: &#x27;.\/public\/index.html&#x27;,\n    }),\n  ],\n};\n<\/code><\/pre>\n<p>\u8fd9\u91cc <code>exposes<\/code> \u66b4\u9732\u4e86 <code>.\/ProductList<\/code> \u7ec4\u4ef6\u4f9b\u5bb9\u5668\u4f7f\u7528\u3002<\/p>\n<h3>3. \u8ba2\u5355\u5b50\u5e94\u7528\uff08orders\uff09<\/h3>\n<p>\u5728 <code>orders<\/code> \u76ee\u5f55\u521b\u5efa <code>webpack.config.js<\/code>\uff08Vue 3 \u7248\u672c\uff09\uff1a<\/p>\n<pre><code class=\"language-javascript\">\nconst HtmlWebpackPlugin = require(&#x27;html-webpack-plugin&#x27;);\nconst { VueLoaderPlugin } = require(&#x27;vue-loader&#x27;);\nconst { ModuleFederationPlugin } = require(&#x27;webpack&#x27;).container;\nconst deps = require(&#x27;.\/package.json&#x27;).dependencies;\n\nmodule.exports = {\n  entry: &#x27;.\/src\/index.js&#x27;,\n  mode: &#x27;development&#x27;,\n  devServer: {\n    port: 3002,\n    historyApiFallback: true,\n  },\n  output: {\n    publicPath: &#x27;auto&#x27;,\n  },\n  module: {\n    rules: [\n      {\n        test: \/\\.vue$\/,\n        use: &#x27;vue-loader&#x27;,\n      },\n      {\n        test: \/\\.js$\/,\n        exclude: \/node_modules\/,\n        use: {\n          loader: &#x27;babel-loader&#x27;,\n          options: {\n            presets: [&#x27;@babel\/preset-env&#x27;],\n          },\n        },\n      },\n    ],\n  },\n  plugins: [\n    new VueLoaderPlugin(),\n    new ModuleFederationPlugin({\n      name: &#x27;orders&#x27;,\n      filename: &#x27;remoteEntry.js&#x27;,\n      exposes: {\n        &#x27;.\/OrderList&#x27;: &#x27;.\/src\/components\/OrderList.vue&#x27;,\n      },\n      shared: {\n        vue: { singleton: true, requiredVersion: deps.vue },\n      },\n    }),\n    new HtmlWebpackPlugin({\n      template: &#x27;.\/public\/index.html&#x27;,\n    }),\n  ],\n};\n<\/code><\/pre>\n<h2>\u7f16\u5199\u5b50\u5e94\u7528\u7ec4\u4ef6<\/h2>\n<h3>\u5546\u54c1\u5217\u8868\u7ec4\u4ef6\uff08products\/src\/components\/ProductList.jsx\uff09<\/h3>\n<pre><code class=\"language-jsx\">\nimport React from &#x27;react&#x27;;\n\nconst ProductList = () =&gt; {\n  const products = [\n    { id: 1, name: &#x27;iPhone 15&#x27;, price: 5999 },\n    { id: 2, name: &#x27;MacBook Pro&#x27;, price: 12999 },\n  ];\n\n  return (\n    &lt;div style={{ padding: &#x27;20px&#x27;, border: &#x27;1px solid #ccc&#x27;, borderRadius: &#x27;8px&#x27; }}&gt;\n      &lt;h2&gt;\u5546\u54c1\u5217\u8868&lt;\/h2&gt;\n      &lt;ul&gt;\n        {products.map((p) =&gt; (\n          &lt;li key={p.id}&gt;\n            {p.name} - \u00a5{p.price}\n          &lt;\/li&gt;\n        ))}\n      &lt;\/ul&gt;\n    &lt;\/div&gt;\n  );\n};\n\nexport default ProductList;\n<\/code><\/pre>\n<h3>\u8ba2\u5355\u5217\u8868\u7ec4\u4ef6\uff08orders\/src\/components\/OrderList.vue\uff09<\/h3>\n<pre><code class=\"language-vue\">\n&lt;template&gt;\n  &lt;div class=&quot;order-list&quot;&gt;\n    &lt;h2&gt;\u8ba2\u5355\u5217\u8868&lt;\/h2&gt;\n    &lt;ul&gt;\n      &lt;li v-for=&quot;order in orders&quot; :key=&quot;order.id&quot;&gt;\n        {{ order.id }} - {{ order.status }}\n      &lt;\/li&gt;\n    &lt;\/ul&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nexport default {\n  name: &#x27;OrderList&#x27;,\n  data() {\n    return {\n      orders: [\n        { id: &#x27;ORD-001&#x27;, status: &#x27;\u5df2\u652f\u4ed8&#x27; },\n        { id: &#x27;ORD-002&#x27;, status: &#x27;\u5f85\u53d1\u8d27&#x27; },\n      ],\n    };\n  },\n};\n&lt;\/script&gt;\n\n&lt;style scoped&gt;\n.order-list {\n  padding: 20px;\n  border: 1px solid #ccc;\n  border-radius: 8px;\n}\n&lt;\/style&gt;\n<\/code><\/pre>\n<h2>\u5bb9\u5668\u5e94\u7528\u96c6\u6210\u5b50\u5e94\u7528<\/h2>\n<p>\u5728 <code>host\/src\/App.jsx<\/code> \u4e2d\u52a8\u6001\u52a0\u8f7d\u8fdc\u7a0b\u7ec4\u4ef6\uff1a<\/p>\n<pre><code class=\"language-jsx\">\nimport React, { Suspense, lazy } from &#x27;react&#x27;;\nimport { BrowserRouter as Router, Routes, Route, Link } from &#x27;react-router-dom&#x27;;\n\nconst ProductList = lazy(() =&gt; import(&#x27;products\/ProductList&#x27;));\nconst OrderList = lazy(() =&gt; import(&#x27;orders\/OrderList&#x27;));\n\nconst App = () =&gt; {\n  return (\n    &lt;Router&gt;\n      &lt;div&gt;\n        &lt;nav&gt;\n          &lt;Link to=&quot;\/&quot;&gt;\u9996\u9875&lt;\/Link&gt; | &lt;Link to=&quot;\/products&quot;&gt;\u5546\u54c1&lt;\/Link&gt; | &lt;Link to=&quot;\/orders&quot;&gt;\u8ba2\u5355&lt;\/Link&gt;\n        &lt;\/nav&gt;\n        &lt;Suspense fallback={&lt;div&gt;\u52a0\u8f7d\u4e2d...&lt;\/div&gt;}&gt;\n          &lt;Routes&gt;\n            &lt;Route path=&quot;\/&quot; element={&lt;div&gt;\u6b22\u8fce\u6765\u5230\u5fae\u524d\u7aef\u540e\u53f0&lt;\/div&gt;} \/&gt;\n            &lt;Route path=&quot;\/products&quot; element={&lt;ProductList \/&gt;} \/&gt;\n            &lt;Route path=&quot;\/orders&quot; element={&lt;OrderList \/&gt;} \/&gt;\n          &lt;\/Routes&gt;\n        &lt;\/Suspense&gt;\n      &lt;\/div&gt;\n    &lt;\/Router&gt;\n  );\n};\n\nexport default App;\n<\/code><\/pre>\n<p>\u6ce8\u610f\uff1a\u8fd9\u91cc\u4f7f\u7528\u4e86 <code>lazy<\/code> \u548c <code>Suspense<\/code> \u5b9e\u73b0\u6309\u9700\u52a0\u8f7d\u8fdc\u7a0b\u7ec4\u4ef6\u3002<\/p>\n<h2>\u8fd0\u884c\u4e0e\u8c03\u8bd5<\/h2>\n<p>\u5206\u522b\u542f\u52a8\u4e09\u4e2a\u5e94\u7528\uff1a<\/p>\n<pre><code class=\"language-bash\">\n# \u7ec8\u7aef1\ncd products &amp;&amp; pnpm start\n\n# \u7ec8\u7aef2\ncd orders &amp;&amp; pnpm start\n\n# \u7ec8\u7aef3\ncd host &amp;&amp; pnpm start\n<\/code><\/pre>\n<p>\u8bbf\u95ee <code>http:\/\/localhost:3000<\/code>\uff0c\u5373\u53ef\u770b\u5230\u5bb9\u5668\u5e94\u7528\u3002\u70b9\u51fb\u5bfc\u822a\uff0c\u4f1a\u52a8\u6001\u52a0\u8f7d\u8fdc\u7a0b\u7ec4\u4ef6\u3002<\/p>\n<h2>\u6837\u5f0f\u9694\u79bb\u65b9\u6848<\/h2>\n<p>\u5fae\u524d\u7aef\u4e2d\u6837\u5f0f\u51b2\u7a81\u662f\u5e38\u89c1\u95ee\u9898\u3002\u6211\u4eec\u91c7\u7528\u4ee5\u4e0b\u7b56\u7565\uff1a<\/p>\n<ol>\n<li><strong>CSS Modules<\/strong>\uff1a\u4e3a\u6bcf\u4e2a\u5b50\u5e94\u7528\u7684\u6837\u5f0f\u6587\u4ef6\u4f7f\u7528 <code>.module.css<\/code> \u540e\u7f00\uff0c\u81ea\u52a8\u751f\u6210\u5c40\u90e8\u7c7b\u540d\u3002<\/li>\n<li><strong>Shadow DOM<\/strong>\uff1a\u5bf9\u4e8e\u66f4\u4e25\u683c\u7684\u9694\u79bb\uff0c\u53ef\u4ee5\u4f7f\u7528 Shadow DOM \u5305\u88f9\u5b50\u5e94\u7528\u3002\u4f46\u6ce8\u610f Shadow DOM \u5bf9\u67d0\u4e9b UI \u5e93\u7684\u517c\u5bb9\u6027\u3002<\/li>\n<li><strong>\u547d\u540d\u7a7a\u95f4<\/strong>\uff1a\u4e3a\u6bcf\u4e2a\u5b50\u5e94\u7528\u7684\u6839\u5143\u7d20\u6dfb\u52a0\u552f\u4e00\u7c7b\u540d\uff0c\u6240\u6709\u6837\u5f0f\u5d4c\u5957\u5728\u8be5\u7c7b\u540d\u4e0b\u3002<\/li>\n<\/ol>\n<p>\u5728 Vue \u7ec4\u4ef6\u4e2d\uff0c\u4f7f\u7528 <code><\/p>\n<style scoped><\/code> \u5373\u53ef\u5b9e\u73b0\u7c7b\u4f3c\u6548\u679c\u3002<\/p>\n<h2>\u5e94\u7528\u95f4\u901a\u4fe1<\/h2>\n<p>\u5b50\u5e94\u7528\u4e4b\u95f4\u53ef\u80fd\u9700\u8981\u901a\u4fe1\u3002\u6211\u4eec\u63a8\u8350\u4f7f\u7528 <strong>\u81ea\u5b9a\u4e49\u4e8b\u4ef6<\/strong> \u6216 <strong>\u5171\u4eab\u72b6\u6001\u5e93<\/strong>\u3002<\/p>\n<h3>\u65b9\u6848\u4e00\uff1aCustomEvent<\/h3>\n<p>\u5728\u5bb9\u5668\u4e2d\u6d3e\u53d1\u4e8b\u4ef6\uff0c\u5b50\u5e94\u7528\u76d1\u542c\uff1a<\/p>\n<pre><code class=\"language-javascript\">\n\/\/ \u5bb9\u5668\u4e2d\nwindow.dispatchEvent(new CustomEvent(&#x27;global:message&#x27;, { detail: { text: &#x27;hello&#x27; } }));\n\n\/\/ \u5b50\u5e94\u7528\u4e2d\nwindow.addEventListener(&#x27;global:message&#x27;, (e) =&gt; {\n  console.log(e.detail.text);\n});\n<\/code><\/pre>\n<h3>\u65b9\u6848\u4e8c\uff1a\u5171\u4eab\u72b6\u6001\uff08\u5982 Redux \u6216 Pinia\uff09<\/h3>\n<p>\u901a\u8fc7 Module Federation \u5171\u4eab\u72b6\u6001\u5e93\u5b9e\u4f8b\uff0c\u4f46\u8981\u6ce8\u610f\u7248\u672c\u4e00\u81f4\u6027\u3002<\/p>\n<h2>\u8e29\u5751\u7ecf\u9a8c<\/h2>\n<ul>\n<li><strong>\u5171\u4eab\u4f9d\u8d56\u7248\u672c\u4e0d\u4e00\u81f4<\/strong>\uff1a\u786e\u4fdd <code>shared<\/code> \u4e2d\u58f0\u660e\u7684\u4f9d\u8d56\u7248\u672c\u4e0e\u5b50\u5e94\u7528\u5b9e\u9645\u4f7f\u7528\u7248\u672c\u517c\u5bb9\uff0c\u5426\u5219\u53ef\u80fd\u52a0\u8f7d\u591a\u4e2a\u5b9e\u4f8b\u3002<\/li>\n<li><strong>\u8fdc\u7a0b\u5e94\u7528\u672a\u542f\u52a8<\/strong>\uff1a\u5bb9\u5668\u5e94\u7528\u542f\u52a8\u65f6\u82e5\u8fdc\u7a0b\u5e94\u7528\u672a\u542f\u52a8\uff0c\u4f1a\u62a5\u9519\u3002\u53ef\u901a\u8fc7 <code>lazy<\/code> \u548c\u9519\u8bef\u8fb9\u754c\u5904\u7406\u3002<\/li>\n<li><strong>\u8def\u7531\u51b2\u7a81<\/strong>\uff1a\u5b50\u5e94\u7528\u5185\u90e8\u82e5\u4f7f\u7528\u8def\u7531\uff0c\u9700\u4f7f\u7528 <code>MemoryRouter<\/code> \u6216\u7531\u5bb9\u5668\u7edf\u4e00\u7ba1\u7406\u8def\u7531\u3002<\/li>\n<li><strong>\u6837\u5f0f\u6c61\u67d3<\/strong>\uff1a\u52a1\u5fc5\u4f7f\u7528 CSS Modules \u6216 scoped \u6837\u5f0f\u3002<\/li>\n<li><strong>\u5f00\u53d1\u73af\u5883\u8de8\u57df<\/strong>\uff1a\u786e\u4fdd <code>publicPath<\/code> \u914d\u7f6e\u6b63\u786e\uff0c\u907f\u514d\u8d44\u6e90\u52a0\u8f7d 404\u3002<\/li>\n<\/ul>\n<p>\ud83d\udca1 \u63d0\u793a\uff1a\u751f\u4ea7\u73af\u5883\u90e8\u7f72\u65f6\uff0c\u5c06 <code>remotes<\/code> \u4e2d\u7684\u5730\u5740\u66ff\u6362\u4e3a\u5b9e\u9645\u57df\u540d\uff0c\u5e76\u8003\u8651\u4f7f\u7528\u52a8\u6001\u8fdc\u7a0b\u5165\u53e3\uff08\u901a\u8fc7\u63a5\u53e3\u83b7\u53d6\uff09\u3002<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u672c\u6587\u901a\u8fc7\u4e00\u4e2a\u5b8c\u6574\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 Webpack 5 Module Federation \u6784\u5efa\u5fae\u524d\u7aef\u67b6\u6784\u3002\u6211\u4eec\u5b9e\u73b0\u4e86\u5bb9\u5668\u4e0e\u5b50\u5e94\u7528\u7684\u96c6\u6210\u3001\u8de8\u6846\u67b6\u7ec4\u4ef6\u5171\u4eab\u3001\u6837\u5f0f\u9694\u79bb\u548c\u901a\u4fe1\u3002\u5fae\u524d\u7aef\u4e0d\u662f\u94f6\u5f39\uff0c\u9002\u5408\u56e2\u961f\u89c4\u6a21\u8f83\u5927\u3001\u9700\u8981\u72ec\u7acb\u90e8\u7f72\u7684\u573a\u666f\u3002\u4e0b\u4e00\u6b65\uff0c\u4f60\u53ef\u4ee5\u63a2\u7d22\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 <strong>qiankun<\/strong> \u6216 <strong>single-spa<\/strong> \u4f5c\u4e3a\u66ff\u4ee3\u65b9\u6848\u3002<\/li>\n<li>\u5b9e\u73b0 <strong>\u52a8\u6001\u8fdc\u7a0b\u5165\u53e3<\/strong>\uff0c\u4ece\u914d\u7f6e\u4e2d\u5fc3\u52a0\u8f7d\u5b50\u5e94\u7528\u5217\u8868\u3002<\/li>\n<li>\u96c6\u6210 <strong>Monorepo<\/strong> \u7ba1\u7406\u591a\u4e2a\u5b50\u5e94\u7528\u3002<\/li>\n<\/ul>\n<p>\u5e0c\u671b\u672c\u6587\u80fd\u5e2e\u52a9\u4f60\u987a\u5229\u843d\u5730\u524d\u7aef\u5fae\u670d\u52a1\u67b6\u6784\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u6df1\u5165\u63a2\u8ba8\u524d\u7aef\u5fae\u670d\u52a1\u67b6\u6784\u7684\u843d\u5730\u5b9e\u8df5\uff0c\u4ee5 Webpack 5 Module Federation \u4e3a\u6838\u5fc3\uff0c\u624b\u628a\u624b\u5e26\u4f60\u642d\u5efa\u4e00\u4e2a\u53ef\u72ec\u7acb\u5f00\u53d1\u3001\u90e8\u7f72\u548c\u96c6\u6210\u7684\u5fae\u524d\u7aef\u7cfb\u7edf\u3002\u6db5\u76d6\u67b6\u6784\u8bbe\u8ba1\u3001\u4ee3\u7801\u5b9e\u73b0\u3001\u901a\u4fe1\u673a\u5236\u4e0e\u8e29\u5751\u7ecf\u9a8c\uff0c\u52a9\u4f60\u638c\u63e1\u5fae\u524d\u7aef\u7684\u6838\u5fc3\u8981\u70b9\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[268,162,171,267,55],"class_list":["post-299","post","type-post","status-publish","format-standard","hentry","category-3","category-4","tag-module-federation","tag-webpack","tag-171","tag-267","tag-55"],"_links":{"self":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts\/299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=299"}],"version-history":[{"count":0,"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts\/299\/revisions"}],"wp:attachment":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}