Skip to content

Commit

Permalink
fix: #39 #44 #45 (#46)
Browse files Browse the repository at this point in the history
* fix: pre-bunding

* feat: add pre-bunding subdependencies demo

* fix: exposes .

* fix: remotes support namespace
  • Loading branch information
zhangHongEn committed Aug 10, 2024
1 parent 47598e1 commit 4a73cd4
Show file tree
Hide file tree
Showing 46 changed files with 1,156 additions and 423 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "examples-rust",
"name": "examples-rust-vite-rust",
"version": "1.0.0",
"scripts": {
"dev": "rsbuild dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { pluginReact } from '@rsbuild/plugin-react';

export default defineConfig({
server: {
port: 5176,
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:5176',
assetPrefix: 'http://localhost:5172',
},
tools: {
rspack: (config, { appendPlugins }) => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "examples-vite",
"name": "examples-rust-vite-vite",
"version": "0.0.3",
"type": "module",
"scripts": {
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import topLevelAwait from 'vite-plugin-top-level-await';
export default defineConfig({
server: {
open: true,
port: 5173,
},
base: 'http://localhost:5173',
plugins: [
Expand All @@ -20,7 +21,7 @@ export default defineConfig({
'remote1@https://unpkg.com/react-manifest-example_remote1@1.0.6/dist/mf-manifest.json',
},
exposes: {
App: './src/App.jsx',
'./App': './src/App.jsx',
},
filename: 'dd/remoteEntry.js',
shared: {
Expand Down
26 changes: 26 additions & 0 deletions examples/vite-vite/vite-host/.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/vite-vite/vite-host/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>
24 changes: 24 additions & 0 deletions examples/vite-vite/vite-host/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "examples-vite-vite-host",
"version": "0.0.3",
"type": "module",
"scripts": {
"dev": "vite --force",
"build": "vite build",
"preview": "vite build && http-server --cors -p 5173 dist"
},
"dependencies": {
"@module-federation/vite": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.2.0",
"vue": "^3.4.35",
"vue-router": "^4.4.0"
},
"devDependencies": {
"@swc/core": "~1.6.0",
"@vitejs/plugin-react": "^4.3.1",
"vite": "^5.3.1",
"vite-plugin-top-level-await": "^1.4.1",
"http-server": "^14.1.1"
}
}
10 changes: 10 additions & 0 deletions examples/vite-vite/vite-host/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import RemoteApp from "@namespace/viteViteRemote";

export default function () {
return (
<div>
vite host
<RemoteApp />
</div>
);
}
1 change: 1 addition & 0 deletions examples/vite-vite/vite-host/src/assets/vue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions examples/vite-vite/vite-host/src/main.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

//@ts-ignore
const root = ReactDOM.createRoot(document.getElementById('app'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
11 changes: 11 additions & 0 deletions examples/vite-vite/vite-host/src/mfPlugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const runtimePlugin = () => {
return {
name: 'module-federation-example-plugin',
beforeRequest(args) {
console.log('before request hook');
return args;
},
};
};

export default runtimePlugin;
79 changes: 79 additions & 0 deletions examples/vite-vite/vite-host/src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}

h1 {
font-size: 3.2em;
line-height: 1.1;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

.card {
padding: 2em;
}

#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
39 changes: 39 additions & 0 deletions examples/vite-vite/vite-host/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { federation } from '@module-federation/vite';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import topLevelAwait from 'vite-plugin-top-level-await';

// https://vitejs.dev/config/
export default defineConfig({
server: {
open: true,
port: 5175,
},
base: 'http://localhost:5175',
plugins: [
react(),
federation({
name: 'viteViteHost',
remotes: {
'@namespace/viteViteRemote': {
entry: 'http://localhost:5176/remoteEntry.js',
type: 'module',
},
},
filename: 'remoteEntry.js',
shared: {
vue: {},
react: {
requiredVersion: '18',
},
'react-dom': {},
},
runtimePlugins: ['./src/mfPlugins'],
}),
// If you set build.target: "chrome89", you can remove this plugin
false && topLevelAwait(),
],
build: {
target: 'chrome89',
},
});
26 changes: 26 additions & 0 deletions examples/vite-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/vite-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>
25 changes: 25 additions & 0 deletions examples/vite-vite/vite-remote/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "examples-vite-vite-remote",
"version": "0.0.3",
"type": "module",
"scripts": {
"dev": "vite --force",
"build": "vite build",
"preview": "vite build && http-server --cors -p 5176 dist"
},
"dependencies": {
"@module-federation/vite": "workspace:*",
"ag-grid-react": "^32.1.0",
"react": "^18.3.1",
"react-dom": "^18.2.0",
"vue": "^3.4.35",
"vue-router": "^4.4.0"
},
"devDependencies": {
"@swc/core": "~1.6.0",
"@vitejs/plugin-react": "^4.3.1",
"vite": "^5.3.1",
"vite-plugin-top-level-await": "^1.4.1",
"http-server": "^14.1.1"
}
}
10 changes: 10 additions & 0 deletions examples/vite-vite/vite-remote/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { AgGridReact } from "ag-grid-react";

export default function () {
return (
<div>
vite-remote
<AgGridReact />
</div>
);
}
1 change: 1 addition & 0 deletions examples/vite-vite/vite-remote/src/assets/vue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions examples/vite-vite/vite-remote/src/main.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

//@ts-ignore
const root = ReactDOM.createRoot(document.getElementById('app'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
36 changes: 36 additions & 0 deletions examples/vite-vite/vite-remote/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { federation } from '@module-federation/vite';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import topLevelAwait from 'vite-plugin-top-level-await';

// https://vitejs.dev/config/
export default defineConfig({
server: {
open: true,
port: 5176,
},
base: 'http://localhost:5176',
plugins: [
react(),
federation({
name: '@namespace/viteViteRemote',
exposes: {
'./App': './src/App.jsx',
'.': './src/App.jsx',
},
filename: 'remoteEntry.js',
shared: {
vue: {},
react: {
requiredVersion: '18',
},
'react-dom': {},
},
}),
// If you set build.target: "chrome89", you can remove this plugin
false && topLevelAwait(),
],
build: {
target: 'chrome89',
},
});
Loading

0 comments on commit 4a73cd4

Please sign in to comment.