micro-front-end
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.9 KiB

  1. const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
  2. const mf = require("@angular-architects/module-federation/webpack");
  3. const path = require("path");
  4. const share = mf.share;
  5. const sharedMappings = new mf.SharedMappings();
  6. sharedMappings.register(path.join(__dirname, "tsconfig.json"), []);
  7. module.exports = {
  8. output: {
  9. uniqueName: "mfe1",
  10. publicPath: "http://localhost:3001/",
  11. },
  12. optimization: {
  13. runtimeChunk: false,
  14. },
  15. resolve: {
  16. alias: {
  17. ...sharedMappings.getAliases(),
  18. },
  19. },
  20. plugins: [
  21. new ModuleFederationPlugin({
  22. name: "mfe1",
  23. filename: "remoteEntry.js",
  24. exposes: {
  25. "./Module": "./src/app/microfrontend/microfrontend.module.ts",
  26. },
  27. shared: share({
  28. "assets/img": { eager: true },
  29. "@angular/core": {
  30. singleton: true,
  31. strictVersion: true,
  32. requiredVersion: "auto",
  33. },
  34. "@angular/common": {
  35. singleton: true,
  36. strictVersion: true,
  37. requiredVersion: "auto",
  38. },
  39. "@angular/common/http": {
  40. singleton: true,
  41. strictVersion: true,
  42. requiredVersion: "auto",
  43. },
  44. "@angular/router": {
  45. singleton: true,
  46. strictVersion: true,
  47. requiredVersion: "auto",
  48. },
  49. "my-shared": {
  50. singleton: true,
  51. strictVersion: true,
  52. import: "my-shared", // 对应库的npm包名或本地路径
  53. requiredVersion: "*", // 或者具体的版本号,如"0.0.1"
  54. },
  55. ...sharedMappings.getDescriptors(),
  56. }),
  57. }),
  58. sharedMappings.getPlugin(),
  59. ],
  60. module: {
  61. rules: [
  62. {
  63. test: /\.(png|jpg|gif)$/,
  64. use: [
  65. {
  66. loader: "url-loader",
  67. options: {
  68. limit: 8192, // 将小于 8kb 的图片转为 base64
  69. },
  70. },
  71. ],
  72. },
  73. ],
  74. },
  75. };