-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Build/Test Tools: Restore React Refresh scripts for hot reloading #10725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| const TerserPlugin = require( 'terser-webpack-plugin' ); | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| const { baseDir } = require( './shared' ); | ||
|
|
||
| /** | ||
| * Webpack configuration for development scripts (React Refresh). | ||
| * | ||
| * These scripts enable hot module replacement for block development | ||
| * when using `@wordpress/scripts` with the `--hot` flag. | ||
| * | ||
| * @param {Object} env Environment options. | ||
| * @param {string} env.buildTarget Build target directory. | ||
| * @param {boolean} env.watch Whether to watch for changes. | ||
| * @return {Object} Webpack configuration object. | ||
| */ | ||
| module.exports = function( env = { buildTarget: 'src/', watch: false } ) { | ||
| const buildTarget = env.buildTarget || 'src/'; | ||
|
|
||
| const entry = { | ||
| // React Refresh runtime - exposes ReactRefreshRuntime global. | ||
| [ buildTarget + 'wp-includes/js/dist/development/react-refresh-runtime.js' ]: { | ||
| import: 'react-refresh/runtime', | ||
| library: { | ||
| name: 'ReactRefreshRuntime', | ||
| type: 'window', | ||
| }, | ||
| }, | ||
| [ buildTarget + 'wp-includes/js/dist/development/react-refresh-runtime.min.js' ]: { | ||
| import: 'react-refresh/runtime', | ||
| library: { | ||
| name: 'ReactRefreshRuntime', | ||
| type: 'window', | ||
| }, | ||
| }, | ||
| // React Refresh entry - injects runtime into global hook before React loads. | ||
| [ buildTarget + 'wp-includes/js/dist/development/react-refresh-entry.js' ]: | ||
| '@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js', | ||
| [ buildTarget + 'wp-includes/js/dist/development/react-refresh-entry.min.js' ]: | ||
| '@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js', | ||
|
Comment on lines
+41
to
+45
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have these in Gutenberg, why not use them from there?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have them only when we have the built files in |
||
| }; | ||
|
|
||
| return { | ||
| target: 'browserslist', | ||
| // Must use development mode to preserve process.env.NODE_ENV checks | ||
| // in the source files. These scripts are only used during development. | ||
| mode: 'development', | ||
| devtool: false, | ||
| cache: true, | ||
| entry, | ||
| output: { | ||
| path: baseDir, | ||
| filename: '[name]', | ||
| }, | ||
| optimization: { | ||
| minimize: true, | ||
| moduleIds: 'deterministic', | ||
| minimizer: [ | ||
| new TerserPlugin( { | ||
| include: /\.min\.js$/, | ||
| extractComments: false, | ||
| } ), | ||
| ], | ||
| }, | ||
| watch: env.watch, | ||
| }; | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we backport this to Gutenberg to avoid 404 errors as mentioned in WordPress/gutenberg#74618 (comment)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need, this is only missing in WordPress trunk, which will get updated once this commit lands.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we don't register those in Gutenberg to override the Core scripts. Which means that the ones in Gutenberg are never actually loaded. That is the reason I had to write Step 10 in the Testing Instructions in WordPress/gutenberg#74618 to load the scripts from Gutenberg to be able to test them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should remove the ones in Gutenberg entirely.