(feat): make react and react-dom external#54
Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds React and ReactDOM externalization to the Vite configuration to prevent bundling these libraries by referencing WordPress's global versions available through wp-element.
- Integrates vite-plugin-externals to externalize React dependencies
- Maps react and react-dom to global window.React and window.ReactDOM
- Adds vite-plugin-externals as a new dependency
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/vite-config/src/configs/brave.js | Adds externals plugin configuration to reference global React instances |
| packages/vite-config/package.json | Adds vite-plugin-externals dependency |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| viteExternalsPlugin( { | ||
| react: 'React', | ||
| 'react-dom': 'ReactDOM', |
There was a problem hiding this comment.
The external mapping assumes WordPress provides React and ReactDOM at window.React and window.ReactDOM, but WordPress wp-element actually provides them at window.wp.element.Component and window.wp.element.render. You should verify the correct global variable names or add runtime checks to ensure compatibility.
| viteExternalsPlugin( { | |
| react: 'React', | |
| 'react-dom': 'ReactDOM', | |
| // Map React and ReactDOM to WordPress' wp.element global to avoid duplicate React instances. | |
| viteExternalsPlugin( { | |
| react: 'wp.element', | |
| 'react-dom': 'wp.element', |
There was a problem hiding this comment.
volgens mij praat hij poep
WybeBosch
left a comment
There was a problem hiding this comment.
Goed bezuggg yvettje.
handig dat de viteExternalsPlugin alle react imports veranderd naar de window nu ! :D
e821153 to
c8bd54e
Compare
Dit zorgt ervoor dat
reactenreact-domniet meegebundeld worden, maar gebruik maken van de globale versies die WordPress viawp-elementaanbiedt (viawindow.Reactenwindow.ReactDOM). Net zoals@wordpress/scriptshet doet.Om React en ReactDOM beschikbaar te maken in de frontend, moet je
wp_enqueue_script('wp-element');gebruiken.