From 916b9dd302ee787f4e33b4af1c42a3236543537e Mon Sep 17 00:00:00 2001 From: Daishi Kato Date: Mon, 20 May 2024 07:38:55 +0900 Subject: [PATCH] examples: migrate to vite (#15) --- examples/01_counter/index.html | 9 ++++++ examples/01_counter/package.json | 17 ++++++----- examples/01_counter/public/index.html | 8 ------ examples/01_counter/src/index.tsx | 13 --------- examples/01_counter/src/main.tsx | 10 +++++++ examples/01_counter/tsconfig.json | 15 ++++++++++ examples/02_props/index.html | 9 ++++++ examples/02_props/package.json | 17 ++++++----- examples/02_props/public/index.html | 8 ------ examples/02_props/src/index.tsx | 13 --------- examples/02_props/src/main.tsx | 10 +++++++ examples/02_props/tsconfig.json | 15 ++++++++++ examples/03_async/index.html | 9 ++++++ examples/03_async/package.json | 17 ++++++----- examples/03_async/public/index.html | 8 ------ examples/03_async/src/index.tsx | 13 --------- examples/03_async/src/main.tsx | 10 +++++++ examples/03_async/tsconfig.json | 15 ++++++++++ examples/04_todos/index.html | 9 ++++++ examples/04_todos/package.json | 17 ++++++----- examples/04_todos/public/index.html | 8 ------ examples/04_todos/src/index.tsx | 13 --------- examples/04_todos/src/main.tsx | 10 +++++++ examples/04_todos/tsconfig.json | 15 ++++++++++ examples/05_setvalue/index.html | 9 ++++++ examples/05_setvalue/package.json | 17 ++++++----- examples/05_setvalue/public/index.html | 8 ------ examples/05_setvalue/src/index.tsx | 13 --------- examples/05_setvalue/src/main.tsx | 10 +++++++ examples/05_setvalue/tsconfig.json | 15 ++++++++++ examples/06_r3f/index.html | 9 ++++++ examples/06_r3f/package.json | 20 ++++++------- examples/06_r3f/public/index.html | 8 ------ examples/06_r3f/src/index.tsx | 13 --------- examples/06_r3f/src/main.tsx | 10 +++++++ examples/06_r3f/tsconfig.json | 15 ++++++++++ examples/07_signal/index.html | 9 ++++++ examples/07_signal/package.json | 17 ++++++----- examples/07_signal/public/index.html | 8 ------ examples/07_signal/src/index.tsx | 13 --------- examples/07_signal/src/main.tsx | 10 +++++++ examples/07_signal/tsconfig.json | 15 ++++++++++ vite.config.ts | 39 -------------------------- 43 files changed, 294 insertions(+), 252 deletions(-) create mode 100644 examples/01_counter/index.html delete mode 100644 examples/01_counter/public/index.html delete mode 100644 examples/01_counter/src/index.tsx create mode 100644 examples/01_counter/src/main.tsx create mode 100644 examples/01_counter/tsconfig.json create mode 100644 examples/02_props/index.html delete mode 100644 examples/02_props/public/index.html delete mode 100644 examples/02_props/src/index.tsx create mode 100644 examples/02_props/src/main.tsx create mode 100644 examples/02_props/tsconfig.json create mode 100644 examples/03_async/index.html delete mode 100644 examples/03_async/public/index.html delete mode 100644 examples/03_async/src/index.tsx create mode 100644 examples/03_async/src/main.tsx create mode 100644 examples/03_async/tsconfig.json create mode 100644 examples/04_todos/index.html delete mode 100644 examples/04_todos/public/index.html delete mode 100644 examples/04_todos/src/index.tsx create mode 100644 examples/04_todos/src/main.tsx create mode 100644 examples/04_todos/tsconfig.json create mode 100644 examples/05_setvalue/index.html delete mode 100644 examples/05_setvalue/public/index.html delete mode 100644 examples/05_setvalue/src/index.tsx create mode 100644 examples/05_setvalue/src/main.tsx create mode 100644 examples/05_setvalue/tsconfig.json create mode 100644 examples/06_r3f/index.html delete mode 100644 examples/06_r3f/public/index.html delete mode 100644 examples/06_r3f/src/index.tsx create mode 100644 examples/06_r3f/src/main.tsx create mode 100644 examples/06_r3f/tsconfig.json create mode 100644 examples/07_signal/index.html delete mode 100644 examples/07_signal/public/index.html delete mode 100644 examples/07_signal/src/index.tsx create mode 100644 examples/07_signal/src/main.tsx create mode 100644 examples/07_signal/tsconfig.json diff --git a/examples/01_counter/index.html b/examples/01_counter/index.html new file mode 100644 index 0000000..ec005a3 --- /dev/null +++ b/examples/01_counter/index.html @@ -0,0 +1,9 @@ + + + example + + +
+ + + diff --git a/examples/01_counter/package.json b/examples/01_counter/package.json index bd81ace..e3db7ff 100644 --- a/examples/01_counter/package.json +++ b/examples/01_counter/package.json @@ -2,21 +2,20 @@ "name": "example", "version": "0.0.0", "private": true, - "type": "commonjs", + "type": "module", "dependencies": { - "@types/react": "latest", - "@types/react-dom": "latest", "react": "latest", "react-dom": "latest", - "react-scripts": "latest", - "typescript": "latest", "zustand": "latest", "zustand-signal": "latest" }, + "devDependencies": { + "@types/react": "latest", + "@types/react-dom": "latest", + "typescript": "latest", + "vite": "latest" + }, "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "eject": "react-scripts eject" + "dev": "vite" } } diff --git a/examples/01_counter/public/index.html b/examples/01_counter/public/index.html deleted file mode 100644 index ad4c782..0000000 --- a/examples/01_counter/public/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - example - - -
- - diff --git a/examples/01_counter/src/index.tsx b/examples/01_counter/src/index.tsx deleted file mode 100644 index 10774d1..0000000 --- a/examples/01_counter/src/index.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { StrictMode } from 'react'; -import { createRoot } from 'react-dom/client'; - -import App from './app'; - -const ele = document.getElementById('app'); -if (ele) { - createRoot(ele).render( - - - , - ); -} diff --git a/examples/01_counter/src/main.tsx b/examples/01_counter/src/main.tsx new file mode 100644 index 0000000..1a72c01 --- /dev/null +++ b/examples/01_counter/src/main.tsx @@ -0,0 +1,10 @@ +import { StrictMode } from 'react'; +import { createRoot } from 'react-dom/client'; + +import App from './app'; + +createRoot(document.getElementById('root')!).render( + + + , +); diff --git a/examples/01_counter/tsconfig.json b/examples/01_counter/tsconfig.json new file mode 100644 index 0000000..d387817 --- /dev/null +++ b/examples/01_counter/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "strict": true, + "target": "es2018", + "downlevelIteration": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "bundler", + "skipLibCheck": true, + "allowJs": true, + "noUncheckedIndexedAccess": true, + "exactOptionalPropertyTypes": true, + "jsx": "react-jsx" + } +} diff --git a/examples/02_props/index.html b/examples/02_props/index.html new file mode 100644 index 0000000..ec005a3 --- /dev/null +++ b/examples/02_props/index.html @@ -0,0 +1,9 @@ + + + example + + +
+ + + diff --git a/examples/02_props/package.json b/examples/02_props/package.json index bd81ace..e3db7ff 100644 --- a/examples/02_props/package.json +++ b/examples/02_props/package.json @@ -2,21 +2,20 @@ "name": "example", "version": "0.0.0", "private": true, - "type": "commonjs", + "type": "module", "dependencies": { - "@types/react": "latest", - "@types/react-dom": "latest", "react": "latest", "react-dom": "latest", - "react-scripts": "latest", - "typescript": "latest", "zustand": "latest", "zustand-signal": "latest" }, + "devDependencies": { + "@types/react": "latest", + "@types/react-dom": "latest", + "typescript": "latest", + "vite": "latest" + }, "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "eject": "react-scripts eject" + "dev": "vite" } } diff --git a/examples/02_props/public/index.html b/examples/02_props/public/index.html deleted file mode 100644 index ad4c782..0000000 --- a/examples/02_props/public/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - example - - -
- - diff --git a/examples/02_props/src/index.tsx b/examples/02_props/src/index.tsx deleted file mode 100644 index 10774d1..0000000 --- a/examples/02_props/src/index.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { StrictMode } from 'react'; -import { createRoot } from 'react-dom/client'; - -import App from './app'; - -const ele = document.getElementById('app'); -if (ele) { - createRoot(ele).render( - - - , - ); -} diff --git a/examples/02_props/src/main.tsx b/examples/02_props/src/main.tsx new file mode 100644 index 0000000..1a72c01 --- /dev/null +++ b/examples/02_props/src/main.tsx @@ -0,0 +1,10 @@ +import { StrictMode } from 'react'; +import { createRoot } from 'react-dom/client'; + +import App from './app'; + +createRoot(document.getElementById('root')!).render( + + + , +); diff --git a/examples/02_props/tsconfig.json b/examples/02_props/tsconfig.json new file mode 100644 index 0000000..d387817 --- /dev/null +++ b/examples/02_props/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "strict": true, + "target": "es2018", + "downlevelIteration": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "bundler", + "skipLibCheck": true, + "allowJs": true, + "noUncheckedIndexedAccess": true, + "exactOptionalPropertyTypes": true, + "jsx": "react-jsx" + } +} diff --git a/examples/03_async/index.html b/examples/03_async/index.html new file mode 100644 index 0000000..ec005a3 --- /dev/null +++ b/examples/03_async/index.html @@ -0,0 +1,9 @@ + + + example + + +
+ + + diff --git a/examples/03_async/package.json b/examples/03_async/package.json index bd81ace..e3db7ff 100644 --- a/examples/03_async/package.json +++ b/examples/03_async/package.json @@ -2,21 +2,20 @@ "name": "example", "version": "0.0.0", "private": true, - "type": "commonjs", + "type": "module", "dependencies": { - "@types/react": "latest", - "@types/react-dom": "latest", "react": "latest", "react-dom": "latest", - "react-scripts": "latest", - "typescript": "latest", "zustand": "latest", "zustand-signal": "latest" }, + "devDependencies": { + "@types/react": "latest", + "@types/react-dom": "latest", + "typescript": "latest", + "vite": "latest" + }, "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "eject": "react-scripts eject" + "dev": "vite" } } diff --git a/examples/03_async/public/index.html b/examples/03_async/public/index.html deleted file mode 100644 index ad4c782..0000000 --- a/examples/03_async/public/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - example - - -
- - diff --git a/examples/03_async/src/index.tsx b/examples/03_async/src/index.tsx deleted file mode 100644 index 10774d1..0000000 --- a/examples/03_async/src/index.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { StrictMode } from 'react'; -import { createRoot } from 'react-dom/client'; - -import App from './app'; - -const ele = document.getElementById('app'); -if (ele) { - createRoot(ele).render( - - - , - ); -} diff --git a/examples/03_async/src/main.tsx b/examples/03_async/src/main.tsx new file mode 100644 index 0000000..1a72c01 --- /dev/null +++ b/examples/03_async/src/main.tsx @@ -0,0 +1,10 @@ +import { StrictMode } from 'react'; +import { createRoot } from 'react-dom/client'; + +import App from './app'; + +createRoot(document.getElementById('root')!).render( + + + , +); diff --git a/examples/03_async/tsconfig.json b/examples/03_async/tsconfig.json new file mode 100644 index 0000000..d387817 --- /dev/null +++ b/examples/03_async/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "strict": true, + "target": "es2018", + "downlevelIteration": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "bundler", + "skipLibCheck": true, + "allowJs": true, + "noUncheckedIndexedAccess": true, + "exactOptionalPropertyTypes": true, + "jsx": "react-jsx" + } +} diff --git a/examples/04_todos/index.html b/examples/04_todos/index.html new file mode 100644 index 0000000..ec005a3 --- /dev/null +++ b/examples/04_todos/index.html @@ -0,0 +1,9 @@ + + + example + + +
+ + + diff --git a/examples/04_todos/package.json b/examples/04_todos/package.json index bd81ace..e3db7ff 100644 --- a/examples/04_todos/package.json +++ b/examples/04_todos/package.json @@ -2,21 +2,20 @@ "name": "example", "version": "0.0.0", "private": true, - "type": "commonjs", + "type": "module", "dependencies": { - "@types/react": "latest", - "@types/react-dom": "latest", "react": "latest", "react-dom": "latest", - "react-scripts": "latest", - "typescript": "latest", "zustand": "latest", "zustand-signal": "latest" }, + "devDependencies": { + "@types/react": "latest", + "@types/react-dom": "latest", + "typescript": "latest", + "vite": "latest" + }, "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "eject": "react-scripts eject" + "dev": "vite" } } diff --git a/examples/04_todos/public/index.html b/examples/04_todos/public/index.html deleted file mode 100644 index ad4c782..0000000 --- a/examples/04_todos/public/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - example - - -
- - diff --git a/examples/04_todos/src/index.tsx b/examples/04_todos/src/index.tsx deleted file mode 100644 index 10774d1..0000000 --- a/examples/04_todos/src/index.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { StrictMode } from 'react'; -import { createRoot } from 'react-dom/client'; - -import App from './app'; - -const ele = document.getElementById('app'); -if (ele) { - createRoot(ele).render( - - - , - ); -} diff --git a/examples/04_todos/src/main.tsx b/examples/04_todos/src/main.tsx new file mode 100644 index 0000000..1a72c01 --- /dev/null +++ b/examples/04_todos/src/main.tsx @@ -0,0 +1,10 @@ +import { StrictMode } from 'react'; +import { createRoot } from 'react-dom/client'; + +import App from './app'; + +createRoot(document.getElementById('root')!).render( + + + , +); diff --git a/examples/04_todos/tsconfig.json b/examples/04_todos/tsconfig.json new file mode 100644 index 0000000..d387817 --- /dev/null +++ b/examples/04_todos/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "strict": true, + "target": "es2018", + "downlevelIteration": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "bundler", + "skipLibCheck": true, + "allowJs": true, + "noUncheckedIndexedAccess": true, + "exactOptionalPropertyTypes": true, + "jsx": "react-jsx" + } +} diff --git a/examples/05_setvalue/index.html b/examples/05_setvalue/index.html new file mode 100644 index 0000000..ec005a3 --- /dev/null +++ b/examples/05_setvalue/index.html @@ -0,0 +1,9 @@ + + + example + + +
+ + + diff --git a/examples/05_setvalue/package.json b/examples/05_setvalue/package.json index bd81ace..e3db7ff 100644 --- a/examples/05_setvalue/package.json +++ b/examples/05_setvalue/package.json @@ -2,21 +2,20 @@ "name": "example", "version": "0.0.0", "private": true, - "type": "commonjs", + "type": "module", "dependencies": { - "@types/react": "latest", - "@types/react-dom": "latest", "react": "latest", "react-dom": "latest", - "react-scripts": "latest", - "typescript": "latest", "zustand": "latest", "zustand-signal": "latest" }, + "devDependencies": { + "@types/react": "latest", + "@types/react-dom": "latest", + "typescript": "latest", + "vite": "latest" + }, "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "eject": "react-scripts eject" + "dev": "vite" } } diff --git a/examples/05_setvalue/public/index.html b/examples/05_setvalue/public/index.html deleted file mode 100644 index ad4c782..0000000 --- a/examples/05_setvalue/public/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - example - - -
- - diff --git a/examples/05_setvalue/src/index.tsx b/examples/05_setvalue/src/index.tsx deleted file mode 100644 index 10774d1..0000000 --- a/examples/05_setvalue/src/index.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { StrictMode } from 'react'; -import { createRoot } from 'react-dom/client'; - -import App from './app'; - -const ele = document.getElementById('app'); -if (ele) { - createRoot(ele).render( - - - , - ); -} diff --git a/examples/05_setvalue/src/main.tsx b/examples/05_setvalue/src/main.tsx new file mode 100644 index 0000000..1a72c01 --- /dev/null +++ b/examples/05_setvalue/src/main.tsx @@ -0,0 +1,10 @@ +import { StrictMode } from 'react'; +import { createRoot } from 'react-dom/client'; + +import App from './app'; + +createRoot(document.getElementById('root')!).render( + + + , +); diff --git a/examples/05_setvalue/tsconfig.json b/examples/05_setvalue/tsconfig.json new file mode 100644 index 0000000..d387817 --- /dev/null +++ b/examples/05_setvalue/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "strict": true, + "target": "es2018", + "downlevelIteration": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "bundler", + "skipLibCheck": true, + "allowJs": true, + "noUncheckedIndexedAccess": true, + "exactOptionalPropertyTypes": true, + "jsx": "react-jsx" + } +} diff --git a/examples/06_r3f/index.html b/examples/06_r3f/index.html new file mode 100644 index 0000000..ec005a3 --- /dev/null +++ b/examples/06_r3f/index.html @@ -0,0 +1,9 @@ + + + example + + +
+ + + diff --git a/examples/06_r3f/package.json b/examples/06_r3f/package.json index 9b2f40e..e3db7ff 100644 --- a/examples/06_r3f/package.json +++ b/examples/06_r3f/package.json @@ -2,24 +2,20 @@ "name": "example", "version": "0.0.0", "private": true, - "type": "commonjs", + "type": "module", "dependencies": { - "@react-three/fiber": "latest", - "@react-three/drei": "latest", - "@types/react": "latest", - "@types/react-dom": "latest", "react": "latest", "react-dom": "latest", - "react-scripts": "latest", - "three": "latest", - "typescript": "latest", "zustand": "latest", "zustand-signal": "latest" }, + "devDependencies": { + "@types/react": "latest", + "@types/react-dom": "latest", + "typescript": "latest", + "vite": "latest" + }, "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "eject": "react-scripts eject" + "dev": "vite" } } diff --git a/examples/06_r3f/public/index.html b/examples/06_r3f/public/index.html deleted file mode 100644 index ad4c782..0000000 --- a/examples/06_r3f/public/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - example - - -
- - diff --git a/examples/06_r3f/src/index.tsx b/examples/06_r3f/src/index.tsx deleted file mode 100644 index 10774d1..0000000 --- a/examples/06_r3f/src/index.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { StrictMode } from 'react'; -import { createRoot } from 'react-dom/client'; - -import App from './app'; - -const ele = document.getElementById('app'); -if (ele) { - createRoot(ele).render( - - - , - ); -} diff --git a/examples/06_r3f/src/main.tsx b/examples/06_r3f/src/main.tsx new file mode 100644 index 0000000..1a72c01 --- /dev/null +++ b/examples/06_r3f/src/main.tsx @@ -0,0 +1,10 @@ +import { StrictMode } from 'react'; +import { createRoot } from 'react-dom/client'; + +import App from './app'; + +createRoot(document.getElementById('root')!).render( + + + , +); diff --git a/examples/06_r3f/tsconfig.json b/examples/06_r3f/tsconfig.json new file mode 100644 index 0000000..d387817 --- /dev/null +++ b/examples/06_r3f/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "strict": true, + "target": "es2018", + "downlevelIteration": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "bundler", + "skipLibCheck": true, + "allowJs": true, + "noUncheckedIndexedAccess": true, + "exactOptionalPropertyTypes": true, + "jsx": "react-jsx" + } +} diff --git a/examples/07_signal/index.html b/examples/07_signal/index.html new file mode 100644 index 0000000..ec005a3 --- /dev/null +++ b/examples/07_signal/index.html @@ -0,0 +1,9 @@ + + + example + + +
+ + + diff --git a/examples/07_signal/package.json b/examples/07_signal/package.json index bd81ace..e3db7ff 100644 --- a/examples/07_signal/package.json +++ b/examples/07_signal/package.json @@ -2,21 +2,20 @@ "name": "example", "version": "0.0.0", "private": true, - "type": "commonjs", + "type": "module", "dependencies": { - "@types/react": "latest", - "@types/react-dom": "latest", "react": "latest", "react-dom": "latest", - "react-scripts": "latest", - "typescript": "latest", "zustand": "latest", "zustand-signal": "latest" }, + "devDependencies": { + "@types/react": "latest", + "@types/react-dom": "latest", + "typescript": "latest", + "vite": "latest" + }, "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "eject": "react-scripts eject" + "dev": "vite" } } diff --git a/examples/07_signal/public/index.html b/examples/07_signal/public/index.html deleted file mode 100644 index ad4c782..0000000 --- a/examples/07_signal/public/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - example - - -
- - diff --git a/examples/07_signal/src/index.tsx b/examples/07_signal/src/index.tsx deleted file mode 100644 index 10774d1..0000000 --- a/examples/07_signal/src/index.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { StrictMode } from 'react'; -import { createRoot } from 'react-dom/client'; - -import App from './app'; - -const ele = document.getElementById('app'); -if (ele) { - createRoot(ele).render( - - - , - ); -} diff --git a/examples/07_signal/src/main.tsx b/examples/07_signal/src/main.tsx new file mode 100644 index 0000000..1a72c01 --- /dev/null +++ b/examples/07_signal/src/main.tsx @@ -0,0 +1,10 @@ +import { StrictMode } from 'react'; +import { createRoot } from 'react-dom/client'; + +import App from './app'; + +createRoot(document.getElementById('root')!).render( + + + , +); diff --git a/examples/07_signal/tsconfig.json b/examples/07_signal/tsconfig.json new file mode 100644 index 0000000..d387817 --- /dev/null +++ b/examples/07_signal/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "strict": true, + "target": "es2018", + "downlevelIteration": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "bundler", + "skipLibCheck": true, + "allowJs": true, + "noUncheckedIndexedAccess": true, + "exactOptionalPropertyTypes": true, + "jsx": "react-jsx" + } +} diff --git a/vite.config.ts b/vite.config.ts index 3bc5661..06d5742 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,9 +1,7 @@ /// import { resolve } from 'node:path'; -import { readFileSync } from 'node:fs'; import { defineConfig } from 'vite'; -import type { Plugin } from 'vite'; const { DIR, PORT = '8080' } = process.env; @@ -24,42 +22,5 @@ export default defineConfig(({ mode }) => { root: resolve('examples', DIR), server: { port: Number(PORT) }, resolve: { alias: { 'zustand-signal': resolve('src') } }, - plugins: [indexHtml(resolve('examples', DIR, 'public', 'index.html'))], }; }); - -function indexHtml(file: string): Plugin { - const html = readFileSync(file, 'utf8'); - return { - name: 'index-html-plugin', - configureServer(server) { - return () => { - server.middlewares.use((req, res) => { - server - .transformIndexHtml(req.url || '', html) - .then((content) => { - res.statusCode = 200; - res.setHeader('content-type', 'text/html; charset=utf-8'); - res.end(content); - }) - .catch((err) => { - console.error('Error transforming index.html', err); - res.statusCode = 500; - res.end('Internal Server Error'); - }); - }); - }; - }, - config() { - return { optimizeDeps: { entries: ['src/index'] } }; - }, - transformIndexHtml() { - return [ - { - tag: 'script', - attrs: { type: 'module', src: '/src/index' }, - }, - ]; - }, - }; -}