@module-federation/vite 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,86 +17,120 @@ This plugin makes Module Federation work together with [Vite](https://vitejs.dev
17
17
 
18
18
  ### [More examples here](https://github.com/module-federation/vite/tree/main/examples)<br>
19
19
 
20
- ```
21
- pnpm install && pnpm run dev-vv # vite+vite dev demo
22
- ```
20
+ ## Try this crazy example with all these bundlers together
23
21
 
24
- ```
25
- pnpm install && pnpm run preview-vv # vite+vite build demo
22
+ <img src="./docs/multi-example.png"/>
23
+
24
+ <p float="left">
25
+ <img src="./docs/vite.webp" width="150" />
26
+ <img src="./docs/webpack.webp" width="160" />
27
+ <img src="./docs/rspack.webp" width="200" />
28
+ </p>
29
+
30
+ ```bash
31
+ pnpm install
32
+ pnpm run build
33
+ pnpm run multi-example
26
34
  ```
27
35
 
28
36
  ## Getting started 🚀
29
37
 
30
38
  https://module-federation.io/guide/basic/webpack.html
31
39
 
32
- ```js
33
- // vite.config.js
40
+ With **@module-federation/vite**, the process becomes delightfully simple, you will only find the differences from a normal Vite configuration.
41
+
42
+ > This example is with [Vue.js](https://vuejs.org/)</br>
43
+ > The @module-federation/vite configuration remains the same for different frameworks.
44
+
45
+ ## The Remote Application configuration
46
+
47
+ file: **remote/vite.config.ts**
48
+
49
+ ```ts
34
50
  import { defineConfig } from 'vite';
35
- import vue from '@vitejs/plugin-vue';
36
- import { federation } from '@module-federation/vite';
37
- import topLevelAwait from 'vite-plugin-top-level-await';
51
+ import { federation } from '@module-federation/vite'; 👈
38
52
 
39
- // https://vitejs.dev/config/
40
53
  export default defineConfig({
54
+ [...]
41
55
  plugins: [
42
- federation({
43
- name: 'bbc',
44
- remotes: {
45
- mfapp01: 'mfapp01@https://unpkg.com/mf-app-01@1.0.9/dist/remoteEntry.js',
46
- remote2: 'mfapp02@https://unpkg.com/mf-app-02/dist/remoteEntry.js',
47
- remote3:
48
- 'remote1@https://unpkg.com/react-manifest-example_remote1@1.0.6/dist/mf-manifest.json',
49
- // "remote4": {
50
- // entry: "http://localhost:xxxx/remoteEntry.js",
51
- // globalEntryName: "xxxx",
52
- // type: "module"
53
- // }
54
- },
56
+ [...]
57
+ federation({ 👈
58
+ name: "remote",
59
+ filename: "remoteEntry.js",
55
60
  exposes: {
56
- './App': './src/App.vue',
61
+ "./remote-app": "./src/App.vue",
57
62
  },
58
- filename: 'remoteEntry-[hash].js',
59
- // https://github.com/module-federation/vite/issues/87
60
- manifest: true,
61
- shared: {
62
- vue: {},
63
- react: {
64
- requiredVersion: '18',
65
- },
66
- 'react-dom': {
67
- requiredVersion: '18',
68
- },
69
- 'react-dom/': {
70
- requiredVersion: '18',
63
+ shared: ["vue"],
64
+ }),
65
+ ],
66
+ // Do you need to support build targets lower than chrome89?
67
+ // You can use 'vite-plugin-top-level-await' plugin for that.
68
+ build: {
69
+ target: 'chrome89',
70
+ },
71
+ [...]
72
+ });
73
+ ```
74
+
75
+ In this remote app configuration, we define a remoteEntry.js file that will expose the App component.
76
+ The shared property ensures that both host and remote applications use the same vue library.
77
+
78
+ ## The Host Application configuration
79
+
80
+ file **host/vite.config.ts**
81
+
82
+ ```ts
83
+ import { defineConfig } from 'vite';
84
+ import { federation } from '@module-federation/vite'; 👈
85
+
86
+ export default defineConfig({
87
+ [...]
88
+ plugins: [
89
+ [...]
90
+ federation({ 👈
91
+ name: "host",
92
+ remotes: {
93
+ remote: {
94
+ type: "module",
95
+ name: "remote",
96
+ entry: "https://[...]/remoteEntry.js",
97
+ entryGlobalName: "remote",
98
+ shareScope: "default",
71
99
  },
72
100
  },
101
+ filename: "remoteEntry.js",
102
+ shared: ["vue"],
73
103
  }),
74
- // If you set build.target: "chrome89", you can remove this plugin
75
- // topLevelAwait(),
76
104
  ],
77
- server: {
78
- port: 5173,
79
- // dev mode please set origin
80
- origin: 'http://localhost:5173',
81
- },
105
+ // Do you need to support build targets lower than chrome89?
106
+ // You can use 'vite-plugin-top-level-await' plugin for that.
82
107
  build: {
83
108
  target: 'chrome89',
84
109
  },
110
+ [...]
85
111
  });
86
112
  ```
87
113
 
88
- ## roadmap
114
+ The host app configuration specifies its name, the filename of its exposed remote entry remoteEntry.js, and importantly, the configuration of the remote application to load.
115
+
116
+ ## Load the Remote App
89
117
 
90
- - ~~feat: generate mf-manifest.json~~
91
- - ✅ ~~feat: support chrome plugin~~
118
+ In your host app, you can now import and use the remote app with **defineAsyncComponent**
92
119
 
93
- * ✅ ~~feat: support runtime plugins~~
94
- * feat: nuxt ssr
120
+ file **host/src/App.vue**
95
121
 
96
- - feat: download remote d.ts
97
- - feat: generate d.ts
98
- - feat: support @vitejs/plugin-legacy
99
- - feat: Another plugin, when only some remote modules are started, automatically completes HMR[(#54)](https://github.com/module-federation/vite/issues/54)
122
+ ```ts
123
+ <script setup lang="ts">
124
+ import { defineAsyncComponent } from "vue";
125
+ const RemoteMFE = defineAsyncComponent( 👈
126
+ () => import("remote/remote-app")
127
+ );
128
+ </script>
129
+
130
+ <template>
131
+ <RemoteMFE v-if="!!RemoteMFE" /> 👈
132
+ </template>
133
+ ```
100
134
 
101
135
  ### So far so good 🎉
102
136