Skip to content

Commit 3815b43

Browse files
docs: add dynamic remote to example (module-federation#148)
1 parent dd525d8 commit 3815b43

28 files changed

+2988
-7520
lines changed

e2e/vite-webpack-rspack/tests/index.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,34 @@ test.describe('Webpack remote', () => {
7171
await expect(furtherRecommendations).toBeVisible();
7272
});
7373
});
74+
75+
test.describe('Dynamic remote', () => {
76+
test('shows dynamic banner on toggle', async ({ page, baseURL }) => {
77+
await page.goto(baseURL!);
78+
const showAdToggle = page.getByRole('checkbox', { name: 'Show Dynamic Ad', exact: true });
79+
80+
const signUpBanner = page.getByRole('heading', { level: 2, name: 'Sign up now!', exact: true });
81+
const specialPromoBanner = page.getByRole('heading', {
82+
level: 2,
83+
name: 'Up to 50% off!',
84+
});
85+
86+
await showAdToggle.check({ force: true });
87+
88+
// Special Promo banner should be visible after toggling
89+
await expect(specialPromoBanner).toBeVisible();
90+
await expect(signUpBanner).not.toBeVisible();
91+
92+
// Toggle again, no banner should be visible
93+
await showAdToggle.uncheck({ force: true });
94+
95+
await expect(signUpBanner).not.toBeVisible();
96+
await expect(specialPromoBanner).not.toBeVisible();
97+
98+
// Toggle again, SignUpBanner should be visible
99+
await showAdToggle.check({ force: true });
100+
101+
await expect(signUpBanner).toBeVisible();
102+
await expect(specialPromoBanner).not.toBeVisible();
103+
});
104+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# React + Vite
2+
3+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4+
5+
Currently, two official plugins are available:
6+
7+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import js from '@eslint/js';
2+
import globals from 'globals';
3+
import react from 'eslint-plugin-react';
4+
import reactHooks from 'eslint-plugin-react-hooks';
5+
import reactRefresh from 'eslint-plugin-react-refresh';
6+
7+
export default [
8+
{ ignores: ['dist'] },
9+
{
10+
files: ['**/*.{js,jsx}'],
11+
languageOptions: {
12+
ecmaVersion: 2020,
13+
globals: globals.browser,
14+
parserOptions: {
15+
ecmaVersion: 'latest',
16+
ecmaFeatures: { jsx: true },
17+
sourceType: 'module',
18+
},
19+
},
20+
settings: { react: { version: '18.3' } },
21+
plugins: {
22+
react,
23+
'react-hooks': reactHooks,
24+
'react-refresh': reactRefresh,
25+
},
26+
rules: {
27+
...js.configs.recommended.rules,
28+
...react.configs.recommended.rules,
29+
...react.configs['jsx-runtime'].rules,
30+
...reactHooks.configs.recommended.rules,
31+
'react/jsx-no-target-blank': 'off',
32+
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
33+
},
34+
},
35+
];
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + React</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.jsx"></script>
12+
</body>
13+
</html>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "multi-example-remote",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"start": "vite",
8+
"build": "vite build",
9+
"lint": "eslint .",
10+
"preview": "vite preview"
11+
},
12+
"dependencies": {
13+
"react": "^18.3.1",
14+
"react-dom": "^18.3.1",
15+
"@module-federation/vite": "workspace:*"
16+
},
17+
"devDependencies": {
18+
"@eslint/js": "^9.9.0",
19+
"@types/react": "^18.3.3",
20+
"@types/react-dom": "^18.3.0",
21+
"@vitejs/plugin-react": "^4.3.1",
22+
"globals": "^15.9.0",
23+
"tailwindcss": "^3.4.13",
24+
"vite": "^5.4.1"
25+
}
26+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import SignUpBanner from './SignUpBanner';
2+
import SpecialPromo from './SpecialPromo';
3+
4+
function App() {
5+
return (
6+
<div>
7+
<SignUpBanner />
8+
<SpecialPromo />
9+
</div>
10+
);
11+
}
12+
13+
export default App;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const SignUpBanner = () => {
2+
return (
3+
<div className="bg-blue-500 text-white p-4 m-4 rounded ring-offset-ring-4 flex justify-between">
4+
<div>
5+
<h2 className="text-xl">Sign up now!</h2>
6+
<p>Get started with our amazing service today.</p>
7+
<button className="bg-white text-blue-500 p-2 rounded mt-2">Sign up</button>
8+
</div>
9+
<img src="https://picsum.photos/200/200" alt="Random" className="mt-2" />
10+
</div>
11+
);
12+
};
13+
14+
export default SignUpBanner;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const SpecialPromo = () => {
2+
return (
3+
<div className="bg-red-500 text-white p-4 m-4 rounded ring-offset-ring-4 flex justify-between">
4+
<div>
5+
<h2 className="text-xl">Up to 50% off!</h2>
6+
<p>Only for a limited time.</p>
7+
</div>
8+
<img src="https://picsum.photos/200/200" alt="Random" className="mt-2" />
9+
</div>
10+
);
11+
};
12+
13+
export default SpecialPromo;

0 commit comments

Comments
 (0)