Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: v1.0.0 #34

Merged
merged 48 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
8dfd32c
feat: new plugin configuration (#28)
zhangHongEn Aug 1, 2024
2902a4a
init ts (#29)
zhangHongEn Aug 1, 2024
34a2a7e
feat: support runtime plugins (#30)
smelukov Aug 2, 2024
694a27d
fix: Ensure @module-federation/runtime singleton (#31)
zhangHongEn Aug 3, 2024
e50f397
Merge branch 'main' into new-config
gioboa Aug 4, 2024
7730866
Merge branch 'main' into new-config
gioboa Aug 4, 2024
dec3b9b
feat: add packageManager
gioboa Aug 4, 2024
7c3ba59
fix: remoteEntry support hash; format dynamic es module (#35)
zhangHongEn Aug 5, 2024
4c88533
1.0.0-alpha-7c3ba59
gioboa Aug 5, 2024
dabfcab
fix: remove default export (#37)
husayt Aug 6, 2024
8521033
fix: remove pkg-pr-new
gioboa Aug 6, 2024
ffc6e23
chore: add PR title check
gioboa Aug 6, 2024
5fccb3c
1.0.0-alpha-ffc6e23
gioboa Aug 6, 2024
54ad191
fix: #36 and dynamic import (#38)
zhangHongEn Aug 6, 2024
80b7215
1.0.0-alpha-54ad191
gioboa Aug 6, 2024
47598e1
1.0.0-alpha-80b7215
gioboa Aug 6, 2024
4a73cd4
fix: #39 #44 #45 (#46)
zhangHongEn Aug 10, 2024
6c2616f
1.0.0-alpha-4a73cd4
gioboa Aug 10, 2024
10dfd75
fix: windows remoteEntry error (#48)
zhangHongEn Aug 11, 2024
def937d
feat: updated examples (#50)
husayt Aug 11, 2024
a98e167
1.0.0-alpha-def937d
gioboa Aug 11, 2024
c7c2615
fix updated examples (#51)
husayt Aug 12, 2024
10e1f83
fix: #47 (#53)
zhangHongEn Aug 13, 2024
a4dcdd3
1.0.0-alpha-10e1f83
gioboa Aug 13, 2024
c4482ec
improved examples with MUI and etc (#55)
husayt Aug 15, 2024
6cae9ab
fix: #56 #41 (#58)
zhangHongEn Aug 15, 2024
b596618
1.0.0-alpha-6cae9ab
gioboa Aug 15, 2024
0ffffa4
mfruntime update and new examples (#62)
husayt Aug 16, 2024
51eeeb6
fix: #61 (#63)
zhangHongEn Aug 19, 2024
9ec5af0
1.0.0-alpha-51eeeb6
gioboa Aug 19, 2024
f87d7d3
feat: shared-slash (#67)
zhangHongEn Aug 29, 2024
d3487be
1.0.0-alpha-f87d7d3
gioboa Aug 29, 2024
661e052
fix: nx #40 (#69)
zhangHongEn Aug 29, 2024
0c81226
1.0.0-alpha-661e052
gioboa Aug 29, 2024
1aa30c0
fix: #68 (#71)
zhangHongEn Aug 31, 2024
c4a5f89
1.0.0-alpha-1aa30c0
gioboa Aug 31, 2024
ae5c612
fix: monorepo (#72)
zhangHongEn Aug 31, 2024
785fdd6
feat: add Nuxt example (#75)
David-Sellen Sep 3, 2024
49cfabc
chore: update module federation and more examples (#81)
husayt Sep 4, 2024
2322abb
fix: #78 (#79)
zhangHongEn Sep 4, 2024
2f53b4e
fix: #77 (#82)
zhangHongEn Sep 4, 2024
3f3fe6f
1.0.0-alpha-2f53b4e
gioboa Sep 7, 2024
bd8957c
docs: update Vue example link
gioboa Sep 8, 2024
e99f7a9
docs: update React example link
gioboa Sep 8, 2024
cb9311e
docs: update README
gioboa Sep 8, 2024
c13dc95
fix: Remote virtual module path (#84)
zhangHongEn Sep 10, 2024
4291753
1.0.0-alpha-c13dc95
gioboa Sep 10, 2024
56bf77c
feat: add improvements (#86)
zhangHongEn Sep 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions .github/workflows/CI-CD.yml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Validate PR title

on:
pull_request:
branches:
- main

permissions:
pull-requests: read

jobs:
############ SEMANTIC PR TITLE VALIDATION ############
semantic-pr:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules
/lib
dist
.DS_Store
.idea
.__mf__win
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll": true
"source.organizeImports": "explicit",
"source.fixAll": "explicit"
},
"editor.formatOnSave": true
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [1.0.0-alpha-7c3ba59]

### Features

- new configuration based on Module Federation 2.0 via @module-federation/runtime library

# Changelog

## [0.2.8]

### Chores
Expand Down
104 changes: 63 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Vite/Rollup plugin for Module Federation
# Vite plugin for Module Federation
gioboa marked this conversation as resolved.
Show resolved Hide resolved

[![npm](https://img.shields.io/npm/v/@module-federation/vite.svg)](https://www.npmjs.com/package/@module-federation/vite)

## Reason why 🤔

Expand All @@ -9,65 +11,85 @@ This plugin makes Module Federation work together with [Vite](https://vitejs.dev

## Working implementations

### [React](https://github.com/module-federation/module-federation-examples/tree/master/vite-react-microfrontends)<br>
### [Svelte](https://github.com/module-federation/module-federation-examples/tree/master/vite-svelte-microfrontends)<br>
### [Vue](https://github.com/module-federation/module-federation-examples/tree/master/vite-vue-microfrontends)
### [Vue](https://github.com/gioboa/vue-microfrontend-demo)

### [React](https://github.com/gioboa/react-microfrontend-demo)<br>

## Getting started 🚀
### [More examples here](https://github.com/module-federation/vite/tree/main/examples)<br>

```
pnpm install && pnpm run dev-vv # vite+vite dev demo
```

This plugin is based on top of [native-federation](https://www.npmjs.com/package/@softarc/native-federation) so this library is a [peer dependency](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#peerdependencies).
```
pnpm install && pnpm run preview-vv # vite+vite build demo
```

You need to extend the Vite configuration with this plugin:
## Getting started 🚀

```typescript
https://module-federation.io/guide/basic/webpack.html

```js
// vite.config.js
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { federation } from '@module-federation/vite';
import { createEsBuildAdapter } from '@softarc/native-federation-esbuild';
import topLevelAwait from 'vite-plugin-top-level-await';

// https://vitejs.dev/config/
export default defineConfig(async ({ command }) => ({
server: {
fs: {
allow: ['.', '../shared'],
},
},
export default defineConfig({
plugins: [
await federation({
options: {
workspaceRoot: __dirname,
outputPath: 'dist',
tsConfig: 'tsconfig.json',
federationConfig: 'module-federation/federation.config.cjs',
verbose: false,
dev: command === 'serve',
federation({
name: 'bbc',
remotes: {
mfapp01: 'mfapp01@https://unpkg.com/[email protected]/dist/remoteEntry.js',
remote2: 'mfapp02@https://unpkg.com/mf-app-02/dist/remoteEntry.js',
remote3:
'remote1@https://unpkg.com/[email protected]/dist/mf-manifest.json',
// "remote4": {
// entry: "http://localhost:5174/dd/remoteEntry.js",
// globalEntryName: "bb",
// type: "esm"
// }
},
exposes: {
'./App': './src/App.vue',
},
filename: 'dd/remoteEntry.js',
shared: {
vue: {},
react: {
requiredVersion: '18',
},
},
adapter: createEsBuildAdapter({ plugins: [...], }),
}),
[...]
// If you set build.target: "chrome89", you can remove this plugin
// topLevelAwait(),
],
}));
server: {
port: 5173,
// dev mode please set origin
origin: 'http://localhost:5173',
},
build: {
target: 'chrome89',
},
});
```

<br>
## roadmap

### Define configs
- ✅ ~~feat: generate mf-manifest.json~~
- ✅ ~~feat: support chrome plugin~~

You need to define two different configurations in the `federationConfig` property.<br>
Here are two examples:
* ✅ ~~feat: support runtime plugins~~
* feat: nuxt ssr

- [host](https://www.npmjs.com/package/@softarc/native-federation#configuring-hosts)
- [remote](https://www.npmjs.com/package/@softarc/native-federation#configuring-remotes)
<br><br>
- feat: download remote d.ts
- feat: generate d.ts
- feat: support @vitejs/plugin-legacy
- feat: Another plugin, when only some remote modules are started, automatically completes HMR[(#54)](https://github.com/module-federation/vite/issues/54)

### So far so good 🎉

Now you are ready to use Module Federation in Vite!

## Thanks 🤝

Big thanks to:

[Manfred Steyer](https://twitter.com/manfredsteyer), Speaker, Trainer, Consultant and Author with focus on Angular. Google Developer Expert (GDE) and Microsoft MVP.

who collaborate with me to make this possible.
24 changes: 24 additions & 0 deletions examples/nuxt-vite/nuxt-host/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Nuxt dev/build outputs
.output
.data
.nuxt
.nitro
.cache
dist

# Node dependencies
node_modules

# Logs
logs
*.log

# Misc
.DS_Store
.fleet
.idea

# Local env files
.env
.env.*
!.env.example
21 changes: 21 additions & 0 deletions examples/nuxt-vite/nuxt-host/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<div>
<h1>Nuxt host</h1>

<p>
Mode1: <i> {{ runtimeConfig.app.buildId ? ' dev ' : ' prod ' }} mode </i>
</p>
<hr />
</div>
</template>

<script setup>
const runtimeConfig = useRuntimeConfig();

if (process.client) {
// Load remote app on client side
import('@namespace/viteViteRemote/App1').then((app) => {
console.log(app);
});
}
</script>
33 changes: 33 additions & 0 deletions examples/nuxt-vite/nuxt-host/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { federation } from '@module-federation/vite';
import TopAwait from 'vite-plugin-top-level-await';

export default defineNuxtConfig({
compatibilityDate: '2024-04-03',
debug: true,
devtools: { enabled: true },
vite: {
plugins: [
federation({
name: 'nuxhost',
remotes: {
'@namespace/viteViteRemote': 'viteRemote@http://localhost:3000/_nuxt/mf-manifest.json',
},
filename: 'remoteEntry.js',
shared: {
// vue: {},
},
runtimePlugins: ['./utils/mfPlugins'],
// exposes: {
// "./App": "./App.vue"
// }
// manifest: {
// fileName: "_nuxt/mf-manifest.json",
// }
}),
new TopAwait(),
],
build: {
target: 'chrome89',
},
},
});
20 changes: 20 additions & 0 deletions examples/nuxt-vite/nuxt-host/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "examples-nuxt-vite-host",
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"dev": "NODE_OPTIONS=--experimental-vm-modules nuxt dev --experimental-vm-modules --port=3001",
"generate": "nuxt generate",
"preview": "NITRO_PORT=3001 nuxt preview",
"postinstall": "nuxt prepare"
},
"dependencies": {
"nuxt": "^3.13.0",
"vue": "latest",
"@module-federation/vite": "workspace:*"
},
"devDependencies": {
"vite-plugin-top-level-await": "^1.4.4"
}
}
Binary file added examples/nuxt-vite/nuxt-host/public/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions examples/nuxt-vite/nuxt-host/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions examples/nuxt-vite/nuxt-host/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../.nuxt/tsconfig.server.json"
}
4 changes: 4 additions & 0 deletions examples/nuxt-vite/nuxt-host/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// https://nuxt.com/docs/guide/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
}
22 changes: 22 additions & 0 deletions examples/nuxt-vite/nuxt-host/utils/mfPlugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const runtimePlugin = () => {
return {
name: 'module-federation-example-plugin',
beforeInit(args) {
return args;
},
init(args) {
console.log('init: ', args);
return args;
},
beforeLoadShare(args) {
console.log('beforeLoadShare: ', args);
return args;
},
beforeRequest(args) {
console.log('before request hook', args);
return args;
},
};
};

export default runtimePlugin;
24 changes: 24 additions & 0 deletions examples/nuxt-vite/nuxt-remote/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Nuxt dev/build outputs
.output
.data
.nuxt
.nitro
.cache
dist

# Node dependencies
node_modules

# Logs
logs
*.log

# Misc
.DS_Store
.fleet
.idea

# Local env files
.env
.env.*
!.env.example
14 changes: 14 additions & 0 deletions examples/nuxt-vite/nuxt-remote/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<div>
<h1>Nuxt host</h1>

<p>
Mode: <i> {{ runtimeConfig.app.buildId ? ' dev ' : ' prod ' }} mode </i>
</p>
<hr />
</div>
</template>

<script setup>
const runtimeConfig = useRuntimeConfig();
</script>
Loading