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

Updated examples and dependencies #49

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules
/lib
dist
.DS_Store
.idea
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
85 changes: 45 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Vite/Rollup plugin for Module Federation
# Vite plugin for Module Federation

## Reason why 🤔

Expand All @@ -10,64 +10,69 @@ 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/module-federation/module-federation-examples/tree/master/vite-vue-microfrontends)

## Getting started 🚀

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).
https://module-federation.io/guide/basic/webpack.html

You need to extend the Vite configuration with this plugin:

```typescript
```js
// vite.config.js
import { defineConfig } from 'vite';
import { federation } from '@module-federation/vite';
import { createEsBuildAdapter } from '@softarc/native-federation-esbuild';
import vue from '@vitejs/plugin-vue';
import { federation } from 'module-federation-vite';
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(),
],
}));
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~~

- [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

### 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.
29 changes: 29 additions & 0 deletions examples/rust-vite/rust-host/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Rsbuild Project

## Setup

Install the dependencies:

```bash
pnpm install
```

## Get Started

Start the dev server:

```bash
pnpm dev
```

Build the app for production:

```bash
pnpm build
```

Preview the production build locally:

```bash
pnpm preview
```
24 changes: 24 additions & 0 deletions examples/rust-vite/rust-host/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "examples-rust-vite-rust",
"version": "1.0.0",
"scripts": {
"dev": "rsbuild dev",
"build": "rsbuild build",
"preview": "npm run build && http-server --cors -p 5176 dist"
},
"dependencies": {
"@module-federation/enhanced": "0.2.5",
"antd": "^5.16.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.3",
"vue": "^3.4.29"
},
"devDependencies": {
"@rsbuild/core": "0.7.10",
"@rsbuild/plugin-react": "0.7.10",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"typescript": "5.5.3"
}
}
48 changes: 48 additions & 0 deletions examples/rust-vite/rust-host/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

export default defineConfig({
server: {
port: 5172,
open: true,
},
dev: {
// It is necessary to configure assetPrefix, and in the production environment, you need to configure output.assetPrefix
assetPrefix: 'http://localhost:5172',
},
tools: {
rspack: (config, { appendPlugins }) => {
config.output!.uniqueName = 'app1';
appendPlugins([
new ModuleFederationPlugin({
name: 'examples_rust',
remotes: {
viteRemote: 'http://localhost:5173/dd/remoteEntry.js',
},
remoteType: 'module',
exposes: {
'./app': './src/app.tsx',
},
manifest: {
filePath: 'manifestpath',
},
shared: [
'react',
'react-dom',
'vue',
// 'antd'
],
}),
]);
},
},
plugins: [
pluginReact({
splitChunks: {
react: false,
router: false,
},
}),
],
});
11 changes: 11 additions & 0 deletions examples/rust-vite/rust-host/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ViteApp from 'viteRemote/App';

export default function Button() {
return (
<div>
rust host
<hr />
<ViteApp />
</div>
);
}
11 changes: 11 additions & 0 deletions examples/rust-vite/rust-host/src/bootstrap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

//@ts-ignore
const root = ReactDOM.createRoot(document.getElementById('root')!);
root.render(
<React.StrictMode>
<App basename={'/'} />
</React.StrictMode>
);
1 change: 1 addition & 0 deletions examples/rust-vite/rust-host/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@rsbuild/core/types" />
1 change: 1 addition & 0 deletions examples/rust-vite/rust-host/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import('./bootstrap');
16 changes: 16 additions & 0 deletions examples/rust-vite/rust-host/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"baseUrl": "./",
"target": "ES2020",
"lib": ["DOM", "ES2020"],
"module": "ESNext",
"jsx": "react-jsx",
"strict": true,
"skipLibCheck": true,
"isolatedModules": true,
"resolveJsonModule": true,
"moduleResolution": "bundler",
"useDefineForClassFields": true
},
"include": ["src"]
}
26 changes: 26 additions & 0 deletions examples/rust-vite/vite-remote/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

pnpm-lock.yaml

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
13 changes: 13 additions & 0 deletions examples/rust-vite/vite-remote/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
Loading
Loading