@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 +88 -54
- package/lib/index.cjs +134 -150
- package/lib/index.esm.js +134 -150
- package/lib/index.modern.js +148 -164
- package/lib/index.umd.js +134 -150
- package/lib/plugins/pluginDevProxyModuleTopLevelAwait.d.ts +1 -1
- package/lib/plugins/pluginModuleParseEnd.d.ts +1 -1
- package/lib/plugins/pluginProxyRemotes.d.ts +2 -2
- package/lib/utils/__tests__/normalizeModuleFederationOption.test.d.ts +1 -0
- package/lib/utils/logUtils.d.ts +1 -0
- package/lib/utils/normalizeModuleFederationOptions.d.ts +39 -7
- package/lib/virtualModules/index.d.ts +5 -4
- package/lib/virtualModules/virtualExposes.d.ts +2 -0
- package/lib/virtualModules/virtualRuntimeInitStatus.d.ts +1 -1
- package/lib/virtualModules/virtualShared_preBuild.d.ts +5 -5
- package/package.json +11 -4
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
|
-
|
|
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
|
-
|
|
33
|
-
|
|
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
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
61
|
+
"./remote-app": "./src/App.vue",
|
|
57
62
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
|
|
91
|
-
- ✅ ~~feat: support chrome plugin~~
|
|
118
|
+
In your host app, you can now import and use the remote app with **defineAsyncComponent**
|
|
92
119
|
|
|
93
|
-
|
|
94
|
-
* feat: nuxt ssr
|
|
120
|
+
file **host/src/App.vue**
|
|
95
121
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
|