Vite
Lumbermill supports React. Follow these steps to add it to a project.
-
Install React dependencies
Terminal window ddev npm i --save-dev @vitejs/plugin-react @types/react @types/react-domddev npm i react react-dom -
Create
tsconfig.jsonin the theme rootweb/app/themes/lumbermill/tsconfig.json {"compilerOptions": {"target": "ES2020","useDefineForClassFields": true,"lib": ["ES2020", "DOM", "DOM.Iterable"],"module": "ESNext","skipLibCheck": true,/* Bundler mode */"moduleResolution": "bundler","allowImportingTsExtensions": true,"resolveJsonModule": true,"isolatedModules": true,"noEmit": true,"jsx": "react-jsx",/* Linting */"strict": true,"noUnusedLocals": true,"noUnusedParameters": true,"noFallthroughCasesInSwitch": true,"paths": {"@my-app/*": ["./assets/src/js/my-app/src/*"],}},"include": ["./assets/src/js/my-app/src/**/*"]}Replace
my-appwith a logical name for the app. -
Add the entrypoint to
config/entrypoints.jsonconfig/entrypoints.json {"lumbermill": "assets/src/js/site.js","lumbermill-admin": "assets/src/js/admin/main.js","my-app": "assets/src/js/my-app/src/main.tsx"} -
Update
config/assets.phpto enable the React helperconfig/assets.php <?phpreturn ['vite' => ['entrypoints' => [],'helpers' => ['react'],],]; -
Add the React plugin and alias to
vite.config.tsvite.config.ts import react from '@vitejs/plugin-react';// inside plugins array:react(),// inside resolve.alias:'@my-app': __dirname + '/assets/src/js/my-app/src' -
Create the entrypoint file
web/app/themes/lumbermill/assets/src/js/my-app/main.tsx import React from 'react';import ReactDOM from 'react-dom/client';const appEl = document.getElementById('my-app') as HTMLElement;ReactDOM.createRoot(appEl).render(<React.StrictMode><h1>Hello world</h1></React.StrictMode>); -
Add a mount point to a Twig template
{# web/app/themes/lumbermill/views/templates/front-page.twig #}<div id="my-app"></div>

