mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Backports the same changes to the webpack config in the Gutenberg plugin with https://github.com/WordPress/gutenberg/pull/50122. The `warning` function from `@wordpress/warning` no longer worked correctly with webpack 5. In practice, it no longer called `console.warn`. To fix it, the usage of `process.env.NODE_ENV` check got replaced with another optional global: `SCRIPT_DEBUG`. All the tools used in the Gutenberg, get updated to work with this new constant, including `@wordpress/scripts`. This way, developers are able to guard code that should be run only in development mode. In WordPress core, the same constant needs to be added mostly to ensure that the code behind the check gets completely removed in production mode. Fixes #59407. git-svn-id: https://develop.svn.wordpress.org/trunk@56699 602fd350-edb4-49c9-b593-d223f7449a82
95 lines
3.5 KiB
JavaScript
95 lines
3.5 KiB
JavaScript
/**
|
|
* External dependencies
|
|
*/
|
|
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
|
|
|
|
/**
|
|
* WordPress dependencies
|
|
*/
|
|
const DependencyExtractionPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
|
|
|
|
/**
|
|
* Internal dependencies
|
|
*/
|
|
const { baseDir, getBaseConfig, normalizeJoin, stylesTransform } = require( './shared' );
|
|
const {
|
|
isDynamic,
|
|
toDirectoryName,
|
|
getStableBlocksMetadata,
|
|
} = require( '../release/sync-stable-blocks' );
|
|
|
|
module.exports = function( env = { environment: 'production', watch: false, buildTarget: false } ) {
|
|
const mode = env.environment;
|
|
const suffix = mode === 'production' ? '.min' : '';
|
|
let buildTarget = env.buildTarget ? env.buildTarget : ( mode === 'production' ? 'build' : 'src' );
|
|
buildTarget = buildTarget + '/wp-includes';
|
|
|
|
const blocks = getStableBlocksMetadata();
|
|
const dynamicBlockFolders = blocks.filter( isDynamic ).map( toDirectoryName );
|
|
const blockFolders = blocks.map( toDirectoryName );
|
|
const blockPHPFiles = {
|
|
'widgets/src/blocks/legacy-widget/index.php': 'wp-includes/blocks/legacy-widget.php',
|
|
'widgets/src/blocks/widget-group/index.php': 'wp-includes/blocks/widget-group.php',
|
|
...dynamicBlockFolders.reduce( ( files, blockName ) => {
|
|
files[ `block-library/src/${ blockName }/index.php` ] = `wp-includes/blocks/${ blockName }.php`;
|
|
return files;
|
|
}, {} ),
|
|
};
|
|
const blockMetadataFiles = {
|
|
'widgets/src/blocks/legacy-widget/block.json': 'wp-includes/blocks/legacy-widget/block.json',
|
|
'widgets/src/blocks/widget-group/block.json': 'wp-includes/blocks/widget-group/block.json',
|
|
...blockFolders.reduce( ( files, blockName ) => {
|
|
files[ `block-library/src/${ blockName }/block.json` ] = `wp-includes/blocks/${ blockName }/block.json`;
|
|
return files;
|
|
}, {} ),
|
|
};
|
|
|
|
const blockPHPCopies = Object.keys( blockPHPFiles ).map( ( filename ) => ( {
|
|
from: normalizeJoin(baseDir, `node_modules/@wordpress/${ filename }` ),
|
|
to: normalizeJoin(baseDir, `src/${ blockPHPFiles[ filename ] }` ),
|
|
} ) );
|
|
|
|
const blockMetadataCopies = Object.keys( blockMetadataFiles ).map( ( filename ) => ( {
|
|
from: normalizeJoin(baseDir, `node_modules/@wordpress/${ filename }` ),
|
|
to: normalizeJoin(baseDir, `src/${ blockMetadataFiles[ filename ] }` ),
|
|
} ) );
|
|
|
|
const blockStylesheetCopies = blockFolders.map( ( blockName ) => ( {
|
|
from: normalizeJoin(baseDir, `node_modules/@wordpress/block-library/build-style/${ blockName }/*.css` ),
|
|
to: normalizeJoin(baseDir, `${ buildTarget }/blocks/${ blockName }/[name]${ suffix }.css` ),
|
|
transform: stylesTransform( mode ),
|
|
noErrorOnMissing: true,
|
|
} ) );
|
|
|
|
const baseConfig = getBaseConfig( env );
|
|
const config = {
|
|
...baseConfig,
|
|
entry: {
|
|
'file/view': normalizeJoin(baseDir, `node_modules/@wordpress/block-library/build-module/file/view` ),
|
|
'navigation/view': normalizeJoin(baseDir, `node_modules/@wordpress/block-library/build-module/navigation/view` ),
|
|
'navigation/view-modal': normalizeJoin(baseDir, `node_modules/@wordpress/block-library/build-module/navigation/view-modal` ),
|
|
'search/view': normalizeJoin(baseDir, `node_modules/@wordpress/block-library/build-module/search/view` ),
|
|
},
|
|
output: {
|
|
devtoolNamespace: 'wp',
|
|
filename: `[name]${ suffix }.js`,
|
|
path: normalizeJoin(baseDir, `${ buildTarget }/blocks` ),
|
|
},
|
|
plugins: [
|
|
...baseConfig.plugins,
|
|
new DependencyExtractionPlugin( {
|
|
injectPolyfill: false,
|
|
} ),
|
|
new CopyWebpackPlugin( {
|
|
patterns: [
|
|
...blockPHPCopies,
|
|
...blockMetadataCopies,
|
|
...blockStylesheetCopies,
|
|
],
|
|
} ),
|
|
],
|
|
};
|
|
|
|
return config;
|
|
};
|