-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd525d8
commit 44a86e3
Showing
28 changed files
with
2,989 additions
and
7,519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# React + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@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 | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh |
35 changes: 35 additions & 0 deletions
35
examples/vite-webpack-rspack/dynamic-remote/eslint.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import js from '@eslint/js'; | ||
import globals from 'globals'; | ||
import react from 'eslint-plugin-react'; | ||
import reactHooks from 'eslint-plugin-react-hooks'; | ||
import reactRefresh from 'eslint-plugin-react-refresh'; | ||
|
||
export default [ | ||
{ ignores: ['dist'] }, | ||
{ | ||
files: ['**/*.{js,jsx}'], | ||
languageOptions: { | ||
ecmaVersion: 2020, | ||
globals: globals.browser, | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
ecmaFeatures: { jsx: true }, | ||
sourceType: 'module', | ||
}, | ||
}, | ||
settings: { react: { version: '18.3' } }, | ||
plugins: { | ||
react, | ||
'react-hooks': reactHooks, | ||
'react-refresh': reactRefresh, | ||
}, | ||
rules: { | ||
...js.configs.recommended.rules, | ||
...react.configs.recommended.rules, | ||
...react.configs['jsx-runtime'].rules, | ||
...reactHooks.configs.recommended.rules, | ||
'react/jsx-no-target-blank': 'off', | ||
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }], | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + React</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.jsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "multi-example-remote", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"start": "vite", | ||
"build": "vite build", | ||
"lint": "eslint .", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"@module-federation/vite": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.9.0", | ||
"@types/react": "^18.3.3", | ||
"@types/react-dom": "^18.3.0", | ||
"@vitejs/plugin-react": "^4.3.1", | ||
"globals": "^15.9.0", | ||
"tailwindcss": "^3.4.13", | ||
"vite": "^5.4.1" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
examples/vite-webpack-rspack/dynamic-remote/postcss.config.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import SignUpBanner from './SignUpBanner'; | ||
import SpecialPromo from './SpecialPromo'; | ||
|
||
function App() { | ||
return ( | ||
<div> | ||
<SignUpBanner /> | ||
<SpecialPromo /> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
14 changes: 14 additions & 0 deletions
14
examples/vite-webpack-rspack/dynamic-remote/src/SignUpBanner.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const SignUpBanner = () => { | ||
return ( | ||
<div className="bg-blue-500 text-white p-4 m-4 rounded ring-offset-ring-4 flex justify-between"> | ||
<div> | ||
<h2 className="text-xl">Sign up now!</h2> | ||
<p>Get started with our amazing service today.</p> | ||
<button className="bg-white text-blue-500 p-2 rounded mt-2">Sign up</button> | ||
</div> | ||
<img src="https://picsum.photos/200/200" alt="Random" className="mt-2" /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SignUpBanner; |
13 changes: 13 additions & 0 deletions
13
examples/vite-webpack-rspack/dynamic-remote/src/SpecialPromo.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const SpecialPromo = () => { | ||
return ( | ||
<div className="bg-red-500 text-white p-4 m-4 rounded ring-offset-ring-4 flex justify-between"> | ||
<div> | ||
<h2 className="text-xl">Up to 50% off!</h2> | ||
<p>Only for a limited time.</p> | ||
</div> | ||
<img src="https://picsum.photos/200/200" alt="Random" className="mt-2" /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SpecialPromo; |
10 changes: 10 additions & 0 deletions
10
examples/vite-webpack-rspack/dynamic-remote/src/bootstrap.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React, { StrictMode } from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
import App from './App.jsx'; | ||
import './index.css'; | ||
|
||
createRoot(document.getElementById('root')!).render( | ||
<StrictMode> | ||
<App /> | ||
</StrictMode> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import('./bootstrap'); |
8 changes: 8 additions & 0 deletions
8
examples/vite-webpack-rspack/dynamic-remote/tailwind.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** @type {import('tailwindcss').Config} */ | ||
export default { | ||
content: ['./src/**/*.{js,jsx,ts,tsx}'], | ||
theme: { | ||
extend: {}, | ||
}, | ||
plugins: [], | ||
}; |
29 changes: 29 additions & 0 deletions
29
examples/vite-webpack-rspack/dynamic-remote/vite.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { federation } from '@module-federation/vite'; | ||
import react from '@vitejs/plugin-react'; | ||
import { defineConfig } from 'vite'; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [ | ||
react(), | ||
federation({ | ||
name: 'dynamicRemote', | ||
filename: 'remoteEntry.js', | ||
// Modules to expose | ||
exposes: { | ||
'./SignUpBanner': './src/SignUpBanner.jsx', | ||
'./SpecialPromo': './src/SpecialPromo.jsx', | ||
}, | ||
shared: ['react', 'react-dom'], | ||
}), | ||
], | ||
server: { | ||
port: 4002, | ||
}, | ||
build: { | ||
modulePreload: false, | ||
target: 'esnext', | ||
minify: false, | ||
cssCodeSplit: false, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
examples/vite-webpack-rspack/host/src/components/Toggle.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
|
||
interface ToggleProps { | ||
label: string; | ||
checked: boolean; | ||
onValueChange: (checked: boolean) => void; | ||
} | ||
|
||
export const Toggle = ({ checked, label, onValueChange }: ToggleProps) => { | ||
return ( | ||
<label className="inline-flex items-center cursor-pointer"> | ||
<input | ||
checked={checked} | ||
type="checkbox" | ||
value="" | ||
className="sr-only peer" | ||
onChange={(event) => onValueChange(event.target.checked)} | ||
/> | ||
<div className="relative w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div> | ||
<span className="ms-3 text-sm font-medium">{label}</span> | ||
</label> | ||
); | ||
}; |
30 changes: 30 additions & 0 deletions
30
examples/vite-webpack-rspack/host/src/hooks/useDynamicImport.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { loadRemote } from '@module-federation/runtime'; | ||
import { ElementType, useEffect, useState } from 'react'; | ||
|
||
interface DynamicImportProps { | ||
module: string; | ||
scope: string; | ||
} | ||
|
||
export function useDynamicImport({ module, scope }: DynamicImportProps) { | ||
const [component, setComponent] = useState<ElementType | null>(null); | ||
|
||
useEffect(() => { | ||
if (!module || !scope) return; | ||
|
||
const loadComponent = async () => { | ||
try { | ||
const { default: Component } = (await loadRemote(`${scope}/${module}`)) as { | ||
default: ElementType; | ||
}; | ||
setComponent(() => Component); | ||
} catch (error) { | ||
console.error(`Error loading remote module ${scope}/${module}:`, error); | ||
} | ||
}; | ||
|
||
loadComponent(); | ||
}, [module, scope]); | ||
|
||
return component; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import Product from './Product'; | ||
|
||
function App() { | ||
return <></>; | ||
return <Product />; | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import React from 'react'; | ||
import './index.css'; | ||
import Reviews from './Reviews'; | ||
|
||
export const App = () => <></>; | ||
export const App = () => <Reviews />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import { App } from './App'; | ||
|
||
const root = ReactDOM.createRoot(document.getElementById('app')!); | ||
root.render(<App />); |
Oops, something went wrong.