| 1 |
import { defineConfig, esmExternalRequirePlugin } from 'vite'; |
| 2 |
import react from '@vitejs/plugin-react'; |
| 3 |
|
| 4 |
// https://vitejs.dev/config/ |
| 5 |
export default defineConfig({ |
| 6 |
plugins: [react({ |
| 7 |
// Disable automatic runtime injection |
| 8 |
jsxRuntime: 'classic', |
| 9 |
}), |
| 10 |
esmExternalRequirePlugin({ |
| 11 |
external: ['react', 'react-dom', 'react-dom/client', 'react/jsx-runtime'], |
| 12 |
}), |
| 13 |
|
| 14 |
|
| 15 |
], |
| 16 |
build: { |
| 17 |
rolldownOptions: { |
| 18 |
external: ['react', 'react-dom', 'react-dom/client', 'react/jsx-runtime'], |
| 19 |
output: { |
| 20 |
format: "iife", // or "umd" |
| 21 |
globals: { // Ensure we can load react from WP |
| 22 |
react: 'wp.element', |
| 23 |
'react-dom': 'wp.element', |
| 24 |
'react-dom/client': 'wp.element', |
| 25 |
'react-dom/jsx-runtime': 'wp.element', |
| 26 |
}, |
| 27 |
dir: '../../../admin/settings/dist', |
| 28 |
// Necessary to have a consistent output path, so it's easy to reference it when we call wp_enqueue_script(). |
| 29 |
entryFileNames: 'plugin.js', |
| 30 |
chunkFileNames: 'chunk.js', |
| 31 |
manualChunks: undefined |
| 32 |
}, |
| 33 |
} |
| 34 |
} |
| 35 |
}); |
| 36 |
|