mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
The new "Featured Image" enhancement is handled dynamically, so we need to update how the Cover block is handled in the build processa and registered in the code. Props ironprogrammer, costdev, Mamaduka, chaion07. Fixes #55580. git-svn-id: https://develop.svn.wordpress.org/trunk@53212 602fd350-edb4-49c9-b593-d223f7449a82
183 lines
4.7 KiB
JavaScript
183 lines
4.7 KiB
JavaScript
/**
|
|
* External dependencies
|
|
*/
|
|
const { DefinePlugin } = require( 'webpack' );
|
|
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
|
|
const { join } = require( 'path' );
|
|
|
|
/**
|
|
* WordPress dependencies
|
|
*/
|
|
const DependencyExtractionPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
|
|
|
|
/**
|
|
* Internal dependencies
|
|
*/
|
|
const { stylesTransform, baseConfig, baseDir } = require( './shared' );
|
|
|
|
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 dynamicBlockFolders = [
|
|
'archives',
|
|
'avatar',
|
|
'block',
|
|
'calendar',
|
|
'categories',
|
|
'comment-author-name',
|
|
'comment-content',
|
|
'comment-date',
|
|
'comment-edit-link',
|
|
'comment-reply-link',
|
|
'comment-template',
|
|
'comments-pagination',
|
|
'comments-pagination-next',
|
|
'comments-pagination-numbers',
|
|
'comments-pagination-previous',
|
|
'cover',
|
|
'file',
|
|
'gallery',
|
|
'home-link',
|
|
'image',
|
|
'latest-comments',
|
|
'latest-posts',
|
|
'loginout',
|
|
'navigation',
|
|
'navigation-link',
|
|
'navigation-submenu',
|
|
'page-list',
|
|
'pattern',
|
|
'post-author',
|
|
'post-author-biography',
|
|
'post-comments',
|
|
'post-content',
|
|
'post-date',
|
|
'post-excerpt',
|
|
'post-featured-image',
|
|
'post-navigation-link',
|
|
'post-template',
|
|
'post-terms',
|
|
'post-title',
|
|
'query',
|
|
'query-no-results',
|
|
'query-pagination',
|
|
'query-pagination-next',
|
|
'query-pagination-numbers',
|
|
'query-pagination-previous',
|
|
'query-title',
|
|
'read-more',
|
|
'rss',
|
|
'search',
|
|
'shortcode',
|
|
'site-logo',
|
|
'site-tagline',
|
|
'site-title',
|
|
'social-link',
|
|
'tag-cloud',
|
|
'template-part',
|
|
'term-description',
|
|
];
|
|
const blockFolders = [
|
|
'audio',
|
|
'button',
|
|
'buttons',
|
|
'code',
|
|
'column',
|
|
'columns',
|
|
'comments-query-loop',
|
|
'embed',
|
|
'freeform',
|
|
'group',
|
|
'heading',
|
|
'html',
|
|
'list',
|
|
'list-item',
|
|
'media-text',
|
|
'missing',
|
|
'more',
|
|
'nextpage',
|
|
'paragraph',
|
|
'preformatted',
|
|
'pullquote',
|
|
'quote',
|
|
'separator',
|
|
'social-links',
|
|
'spacer',
|
|
'table',
|
|
'text-columns',
|
|
'verse',
|
|
'video',
|
|
...dynamicBlockFolders,
|
|
];
|
|
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: join( baseDir, `node_modules/@wordpress/${ filename }` ),
|
|
to: join( baseDir, `src/${ blockPHPFiles[ filename ] }` ),
|
|
} ) );
|
|
|
|
const blockMetadataCopies = Object.keys( blockMetadataFiles ).map( ( filename ) => ( {
|
|
from: join( baseDir, `node_modules/@wordpress/${ filename }` ),
|
|
to: join( baseDir, `src/${ blockMetadataFiles[ filename ] }` ),
|
|
} ) );
|
|
|
|
const blockStylesheetCopies = blockFolders.map( ( blockName ) => ( {
|
|
from: join( baseDir, `node_modules/@wordpress/block-library/build-style/${ blockName }/*.css` ),
|
|
to: join( baseDir, `${ buildTarget }/blocks/${ blockName }/[name]${ suffix }.css` ),
|
|
transform: stylesTransform( mode ),
|
|
noErrorOnMissing: true,
|
|
} ) );
|
|
|
|
const config = {
|
|
...baseConfig( env ),
|
|
entry: {
|
|
'file/view': join( baseDir, `node_modules/@wordpress/block-library/build-module/file/view` ),
|
|
'navigation/view': join( baseDir, `node_modules/@wordpress/block-library/build-module/navigation/view` ),
|
|
},
|
|
output: {
|
|
devtoolNamespace: 'wp',
|
|
filename: `[name]${ suffix }.js`,
|
|
path: join( baseDir, `${ buildTarget }/blocks` ),
|
|
},
|
|
plugins: [
|
|
new DefinePlugin( {
|
|
// Inject the `GUTENBERG_PHASE` global, used for feature flagging.
|
|
'process.env.GUTENBERG_PHASE': 1,
|
|
'process.env.FORCE_REDUCED_MOTION': JSON.stringify(
|
|
process.env.FORCE_REDUCED_MOTION
|
|
),
|
|
} ),
|
|
new DependencyExtractionPlugin( {
|
|
injectPolyfill: false,
|
|
} ),
|
|
new CopyWebpackPlugin( {
|
|
patterns: [
|
|
...blockPHPCopies,
|
|
...blockMetadataCopies,
|
|
...blockStylesheetCopies,
|
|
],
|
|
} ),
|
|
],
|
|
};
|
|
|
|
return config;
|
|
};
|