Make WordPress Core

source: trunk/tools/webpack/development.js @ 53140

Last change on this file since 53140 was 53140, checked in by gziolo, 2 years ago

Build: Enable React Fast Refresh for block development

Brings the same functionality introduced in the Gutenberg plugin with https://github.com/WordPress/gutenberg/pull/28273. In effect, it brings React Fast Refresh support to WordPress core for block development with @wordpress/scripts.

Props walbo, antonvlasenko.
See #51750, #55505.
Follow-up [53135].

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1/**
2 * External dependencies
3 */
4const { join } = require( 'path' );
5
6/**
7 * WordPress dependencies
8 */
9const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
10
11const baseDir = join( __dirname, '../../' );
12
13module.exports = function( env = { environment: 'production', buildTarget: false } ) {
14        const mode = env.environment;
15        const suffix = mode === 'production' ? '.min' : '';
16        let buildTarget = env.buildTarget ? env.buildTarget : ( mode === 'production' ? 'build' : 'src' );
17        buildTarget = buildTarget  + '/wp-includes';
18
19        const sharedConfig = {
20                mode: 'development',
21                target: 'browserslist',
22                output: {
23                        filename: `[name]${ suffix }.js`,
24                        path: join( baseDir, `${ buildTarget }/js/dist/development` ),
25                },
26        };
27
28        // See https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md#externalising-react.
29        return [
30                {
31                        ...sharedConfig,
32                        name: 'react-refresh-entry',
33                        entry: {
34                                'react-refresh-entry':
35                                '@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js',
36                        },
37                        plugins: [ new DependencyExtractionWebpackPlugin( {
38                                outputFilename: '../../../assets/script-loader-[name].php',
39                        } ) ],
40                },
41                {
42                        ...sharedConfig,
43                        name: 'react-refresh-runtime',
44                        entry: {
45                                'react-refresh-runtime': {
46                                        import: 'react-refresh/runtime.js',
47                                        library: {
48                                                name: 'ReactRefreshRuntime',
49                                                type: 'window',
50                                        },
51                                },
52                        },
53                        plugins: [
54                                new DependencyExtractionWebpackPlugin( {
55                                        useDefaults: false,
56                                        outputFilename: '../../../assets/script-loader-[name].php'
57                                } ),
58                        ],
59                },
60        ];
61};
Note: See TracBrowser for help on using the repository browser.