integrates React with drupal theme

द्वारा admin , 5 अप्रैल, 2026

Step 1: Set Up Your Theme /themes/custom/my_react_theme

Step 2: Initialize Node.js: In your theme's root directory, run npm init -y to create a package.json file.

Step4 : add the build scripts .locate the "scripts" section. Add the "build" and "dev" entries as shown below

{
  "name": "amur",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "vite build",  
    "dev": "vite",  
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^19.2.4",
    "react-dom": "^19.2.4"
  },
  "devDependencies": {
    "@vitejs/plugin-react": "^6.0.1",
    "vite": "^8.0.3"
  }
}


 

Initialize

 

Step4 : create dist and component folder into theme root directory.

Step 3: create and Configure Vite vite.config.js file 

// vite.config.js 

import { defineConfig } from 'vite'; 

import react from '@vitejs/plugin-react'; 

import glob from 'glob'; 

import path from 'path'; 

export default defineConfig({ 

plugins: [react()], 

build: { 

// Automatically find all .jsx files as entry points 

rollupOptions: { 

input: glob.sync(path.resolve(__dirname, 'components/**/*.jsx')), 

output: { 

// Output compiled files to a 'dist' folder in your theme 

dir: 'dist', 

entryFileNames: '[name].js', 

},

 },

 },

 });

Step 4: Connect React to Drupal via SDC

Step 6: Build Your React Component

Standard (Image)

सादा टेक्स्ट

  • No HTML tags allowed.
  • लाइन और पैराग्राफ स्वतः भंजन
  • Web page addresses and email addresses turn into links automatically.