Make WordPress Core

Changeset 44159


Ignore:
Timestamp:
12/14/2018 04:10:26 AM (8 years ago)
Author:
pento
Message:

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.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/.gitignore

    r43348 r44159  
    2020/wp-cli.local.yml
    2121/jsdoc
     22/src/wp-includes/js
     23/src/wp-includes/css/dist
    2224
    2325# Files and folders that get created in wp-content
  • trunk/Gruntfile.js

    r44135 r44159  
    13471347        grunt.registerTask( 'build', [
    13481348                'clean:all',
    1349                 'webpack:dev',
    13501349                'copy:all',
    13511350                'file_append',
     
    13611360                'includes:embed',
    13621361                'usebanner',
     1362                'webpack:prod',
    13631363                'jsvalidate:build'
    13641364        ] );
  • trunk/src/wp-includes

    • Property svn:ignore set to
      js
  • trunk/src/wp-includes/css

    • Property svn:ignore set to
      dist

  • trunk/src/wp-includes/script-loader.php

    r44157 r44159  
    9797                }
    9898
    99                 $path = "/js/dist/vendor/$handle$dev_suffix.js";
     99                $path = "/wp-includes/js/dist/vendor/$handle$dev_suffix.js";
    100100
    101101                $scripts->add( $handle, $path, $dependencies, false, 1 );
     
    337337
    338338        foreach ( $packages_dependencies as $package => $dependencies ) {
    339                 $handle = 'wp-' . $package;
    340                 $path   = "/js/dist/$package$suffix.js";
     339                $handle  = 'wp-' . $package;
     340                $path    = "/wp-includes/js/dist/$package$suffix.js";
    341341
    342342                $scripts->add( $handle, $path, $dependencies, false, 1 );
     
    18011801        $styles->add( 'wp-editor-font', $fonts_url );
    18021802
    1803         $styles->add( 'wp-block-library-theme', '/styles/dist/block-library/theme.css' );
     1803        $styles->add( 'wp-block-library-theme', '/wp-includes/css/dist/block-library/theme.css' );
    18041804        $styles->add_data( 'wp-block-library-theme', 'rtl', 'replace' );
    18051805
    18061806        $styles->add(
    18071807                'wp-edit-blocks',
    1808                 '/styles/dist/block-library/editor.css',
     1808                '/wp-includes/css/dist/block-library/editor.css',
    18091809                array(
    18101810                        'wp-components',
     
    18261826
    18271827        foreach ( $package_styles as $package => $dependencies ) {
    1828                 $handle = 'wp-' . $package;
    1829                 $path   = '/styles/dist/' . $package . '/style.css';
     1828                $handle  = 'wp-' . $package;
     1829                $path     = '/wp-includes/css/dist/' . $package . '/style.css';
    18301830
    18311831                $styles->add( $handle, $path, $dependencies );
  • trunk/tools/webpack/packages.js

    r44118 r44159  
    3838 * Maps vendors to copy commands for the CopyWebpackPlugin.
    3939 *
    40  * @param {Object} vendors Vendors to include in the vendor folder.
     40 * @param {Object} vendors     Vendors to include in the vendor folder.
     41 * @param {string} buildTarget The folder in which to build the packages.
    4142 *
    4243 * @return {Object[]} Copy object suitable for the CopyWebpackPlugin.
    4344 */
    44 function mapVendorCopies( vendors ) {
     45function mapVendorCopies( vendors, buildTarget ) {
    4546        return Object.keys( vendors ).map( ( filename ) => ( {
    4647                from: join( baseDir, `node_modules/${ vendors[ filename ] }` ),
    47                 to: join( baseDir, `build/js/dist/vendor/${ filename }` ),
     48                to: join( baseDir, `${ buildTarget }/js/dist/vendor/${ filename }` ),
    4849        } ) );
    4950}
     
    5152module.exports = function( env = { environment: 'production', watch: false } ) {
    5253        const mode = env.environment;
    53         const suffix = mode === 'production' ? '.min': '';
     54        const suffix = mode === 'production' ? '.min' : '';
     55        const buildTarget = ( mode === 'production' ? 'build' : 'src' ) + '/wp-includes';
    5456
    5557        const packages = [
     
    144146        } );
    145147
    146         const developmentCopies = mapVendorCopies( vendors );
    147         const minifiedCopies = mapVendorCopies( minifiedVendors );
    148         const minifyCopies = mapVendorCopies( minifyVendors ).map( ( copyCommand ) => {
     148        const developmentCopies = mapVendorCopies( vendors, buildTarget );
     149        const minifiedCopies = mapVendorCopies( minifiedVendors, buildTarget );
     150        const minifyCopies = mapVendorCopies( minifyVendors, buildTarget ).map( ( copyCommand ) => {
    149151                return {
    150152                        ...copyCommand,
     
    159161        let cssCopies = packages.map( ( packageName ) => ( {
    160162                from: join( baseDir, `node_modules/@wordpress/${ packageName }/build-style/*.css` ),
    161                 to: join( baseDir, `build/styles/dist/${ packageName }/` ),
     163                to: join( baseDir, `${ buildTarget }/css/dist/${ packageName }/` ),
    162164                flatten: true,
    163165                transform: ( content ) => {
     
    191193                output: {
    192194                        filename: `[basename]${ suffix }.js`,
    193                         path: join( baseDir, 'build/js/dist' ),
     195                        path: join( baseDir, `${ buildTarget }/js/dist` ),
    194196                        library: {
    195197                                root: [ 'wp', '[name]' ]
Note: See TracChangeset for help on using the changeset viewer.