Build Tools: Copy package JavaScript and CSS into wp-includes
.
- `grunt webpack:dev` now copies packages JS into `/src/wp-includes/js/dist`, and CSS into `/src/wp-includes/css/dist`. - `grunt webpack:prod` does the same, but into `/build` instead of `/src`. - `grunt build` now runs the `webpack:prod` task. Merges [43760] from the 5.0 branch to trunk. Props atimmer, pento. Fixes #45119. git-svn-id: https://develop.svn.wordpress.org/trunk@44159 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
67f54c4696
commit
934f0ca2b8
2
.gitignore
vendored
2
.gitignore
vendored
@ -19,6 +19,8 @@ wp-tests-config.php
|
|||||||
/tests/phpunit/build
|
/tests/phpunit/build
|
||||||
/wp-cli.local.yml
|
/wp-cli.local.yml
|
||||||
/jsdoc
|
/jsdoc
|
||||||
|
/src/wp-includes/js
|
||||||
|
/src/wp-includes/css/dist
|
||||||
|
|
||||||
# Files and folders that get created in wp-content
|
# Files and folders that get created in wp-content
|
||||||
/src/wp-content/blogs.dir
|
/src/wp-content/blogs.dir
|
||||||
|
@ -1346,7 +1346,6 @@ module.exports = function(grunt) {
|
|||||||
|
|
||||||
grunt.registerTask( 'build', [
|
grunt.registerTask( 'build', [
|
||||||
'clean:all',
|
'clean:all',
|
||||||
'webpack:dev',
|
|
||||||
'copy:all',
|
'copy:all',
|
||||||
'file_append',
|
'file_append',
|
||||||
'cssmin:core',
|
'cssmin:core',
|
||||||
@ -1360,6 +1359,7 @@ module.exports = function(grunt) {
|
|||||||
'includes:emoji',
|
'includes:emoji',
|
||||||
'includes:embed',
|
'includes:embed',
|
||||||
'usebanner',
|
'usebanner',
|
||||||
|
'webpack:prod',
|
||||||
'jsvalidate:build'
|
'jsvalidate:build'
|
||||||
] );
|
] );
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ function wp_default_packages_vendor( &$scripts ) {
|
|||||||
$dependencies = array();
|
$dependencies = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = "/js/dist/vendor/$handle$dev_suffix.js";
|
$path = "/wp-includes/js/dist/vendor/$handle$dev_suffix.js";
|
||||||
|
|
||||||
$scripts->add( $handle, $path, $dependencies, false, 1 );
|
$scripts->add( $handle, $path, $dependencies, false, 1 );
|
||||||
}
|
}
|
||||||
@ -336,8 +336,8 @@ function wp_default_packages_scripts( &$scripts ) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $packages_dependencies as $package => $dependencies ) {
|
foreach ( $packages_dependencies as $package => $dependencies ) {
|
||||||
$handle = 'wp-' . $package;
|
$handle = 'wp-' . $package;
|
||||||
$path = "/js/dist/$package$suffix.js";
|
$path = "/wp-includes/js/dist/$package$suffix.js";
|
||||||
|
|
||||||
$scripts->add( $handle, $path, $dependencies, false, 1 );
|
$scripts->add( $handle, $path, $dependencies, false, 1 );
|
||||||
}
|
}
|
||||||
@ -1800,12 +1800,12 @@ function wp_default_styles( &$styles ) {
|
|||||||
}
|
}
|
||||||
$styles->add( 'wp-editor-font', $fonts_url );
|
$styles->add( 'wp-editor-font', $fonts_url );
|
||||||
|
|
||||||
$styles->add( 'wp-block-library-theme', '/styles/dist/block-library/theme.css' );
|
$styles->add( 'wp-block-library-theme', '/wp-includes/css/dist/block-library/theme.css' );
|
||||||
$styles->add_data( 'wp-block-library-theme', 'rtl', 'replace' );
|
$styles->add_data( 'wp-block-library-theme', 'rtl', 'replace' );
|
||||||
|
|
||||||
$styles->add(
|
$styles->add(
|
||||||
'wp-edit-blocks',
|
'wp-edit-blocks',
|
||||||
'/styles/dist/block-library/editor.css',
|
'/wp-includes/css/dist/block-library/editor.css',
|
||||||
array(
|
array(
|
||||||
'wp-components',
|
'wp-components',
|
||||||
'wp-editor',
|
'wp-editor',
|
||||||
@ -1825,8 +1825,8 @@ function wp_default_styles( &$styles ) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $package_styles as $package => $dependencies ) {
|
foreach ( $package_styles as $package => $dependencies ) {
|
||||||
$handle = 'wp-' . $package;
|
$handle = 'wp-' . $package;
|
||||||
$path = '/styles/dist/' . $package . '/style.css';
|
$path = '/wp-includes/css/dist/' . $package . '/style.css';
|
||||||
|
|
||||||
$styles->add( $handle, $path, $dependencies );
|
$styles->add( $handle, $path, $dependencies );
|
||||||
$styles->add_data( $handle, 'rtl', 'replace' );
|
$styles->add_data( $handle, 'rtl', 'replace' );
|
||||||
|
@ -37,20 +37,22 @@ function camelCaseDash( string ) {
|
|||||||
/**
|
/**
|
||||||
* Maps vendors to copy commands for the CopyWebpackPlugin.
|
* Maps vendors to copy commands for the CopyWebpackPlugin.
|
||||||
*
|
*
|
||||||
* @param {Object} vendors Vendors to include in the vendor folder.
|
* @param {Object} vendors Vendors to include in the vendor folder.
|
||||||
|
* @param {string} buildTarget The folder in which to build the packages.
|
||||||
*
|
*
|
||||||
* @return {Object[]} Copy object suitable for the CopyWebpackPlugin.
|
* @return {Object[]} Copy object suitable for the CopyWebpackPlugin.
|
||||||
*/
|
*/
|
||||||
function mapVendorCopies( vendors ) {
|
function mapVendorCopies( vendors, buildTarget ) {
|
||||||
return Object.keys( vendors ).map( ( filename ) => ( {
|
return Object.keys( vendors ).map( ( filename ) => ( {
|
||||||
from: join( baseDir, `node_modules/${ vendors[ filename ] }` ),
|
from: join( baseDir, `node_modules/${ vendors[ filename ] }` ),
|
||||||
to: join( baseDir, `build/js/dist/vendor/${ filename }` ),
|
to: join( baseDir, `${ buildTarget }/js/dist/vendor/${ filename }` ),
|
||||||
} ) );
|
} ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function( env = { environment: 'production', watch: false } ) {
|
module.exports = function( env = { environment: 'production', watch: false } ) {
|
||||||
const mode = env.environment;
|
const mode = env.environment;
|
||||||
const suffix = mode === 'production' ? '.min': '';
|
const suffix = mode === 'production' ? '.min' : '';
|
||||||
|
const buildTarget = ( mode === 'production' ? 'build' : 'src' ) + '/wp-includes';
|
||||||
|
|
||||||
const packages = [
|
const packages = [
|
||||||
'api-fetch',
|
'api-fetch',
|
||||||
@ -143,9 +145,9 @@ module.exports = function( env = { environment: 'production', watch: false } ) {
|
|||||||
};
|
};
|
||||||
} );
|
} );
|
||||||
|
|
||||||
const developmentCopies = mapVendorCopies( vendors );
|
const developmentCopies = mapVendorCopies( vendors, buildTarget );
|
||||||
const minifiedCopies = mapVendorCopies( minifiedVendors );
|
const minifiedCopies = mapVendorCopies( minifiedVendors, buildTarget );
|
||||||
const minifyCopies = mapVendorCopies( minifyVendors ).map( ( copyCommand ) => {
|
const minifyCopies = mapVendorCopies( minifyVendors, buildTarget ).map( ( copyCommand ) => {
|
||||||
return {
|
return {
|
||||||
...copyCommand,
|
...copyCommand,
|
||||||
transform: ( content ) => {
|
transform: ( content ) => {
|
||||||
@ -158,7 +160,7 @@ module.exports = function( env = { environment: 'production', watch: false } ) {
|
|||||||
|
|
||||||
let cssCopies = packages.map( ( packageName ) => ( {
|
let cssCopies = packages.map( ( packageName ) => ( {
|
||||||
from: join( baseDir, `node_modules/@wordpress/${ packageName }/build-style/*.css` ),
|
from: join( baseDir, `node_modules/@wordpress/${ packageName }/build-style/*.css` ),
|
||||||
to: join( baseDir, `build/styles/dist/${ packageName }/` ),
|
to: join( baseDir, `${ buildTarget }/css/dist/${ packageName }/` ),
|
||||||
flatten: true,
|
flatten: true,
|
||||||
transform: ( content ) => {
|
transform: ( content ) => {
|
||||||
if ( config.mode === 'production' ) {
|
if ( config.mode === 'production' ) {
|
||||||
@ -190,7 +192,7 @@ module.exports = function( env = { environment: 'production', watch: false } ) {
|
|||||||
}, {} ),
|
}, {} ),
|
||||||
output: {
|
output: {
|
||||||
filename: `[basename]${ suffix }.js`,
|
filename: `[basename]${ suffix }.js`,
|
||||||
path: join( baseDir, 'build/js/dist' ),
|
path: join( baseDir, `${ buildTarget }/js/dist` ),
|
||||||
library: {
|
library: {
|
||||||
root: [ 'wp', '[name]' ]
|
root: [ 'wp', '[name]' ]
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user