Make WordPress Core

Ticket #40894: 40894.2.diff

File 40894.2.diff, 4.9 KB (added by adamsilverstein, 8 years ago)
  • Gruntfile.js

    diff --git Gruntfile.js Gruntfile.js
    index c7e7f73b2b..7328a68253 100644
     
    11/* jshint node:true */
     2const webpackConfig = require( './webpack.config' );
     3
    24module.exports = function(grunt) {
    35        var path = require('path'),
    46                fs = require( 'fs' ),
    57                SOURCE_DIR = 'src/',
    68                BUILD_DIR = 'build/',
    7                 autoprefixer = require('autoprefixer'),
    8                 mediaConfig = {},
    9                 mediaBuilds = ['audiovideo', 'grid', 'models', 'views'];
     9                autoprefixer = require( 'autoprefixer' );
    1010
    1111        // Load tasks.
    1212        require('matchdep').filterDev(['grunt-*', '!grunt-legacy-util']).forEach( grunt.loadNpmTasks );
    1313        // Load legacy utils
    1414        grunt.util = require('grunt-legacy-util');
    1515
    16         mediaBuilds.forEach( function ( build ) {
    17                 var path = SOURCE_DIR + 'wp-includes/js/media';
    18                 mediaConfig[ build ] = { files : {} };
    19                 mediaConfig[ build ].files[ path + '-' + build + '.js' ] = [ path + '/' + build + '.manifest.js' ];
    20         } );
    21 
    2216        // Project configuration.
    2317        grunt.initConfig({
    2418                postcss: {
    module.exports = function(grunt) { 
    157151                                }
    158152                        }
    159153                },
    160                 browserify: mediaConfig,
    161154                sass: {
    162155                        colors: {
    163156                                expand: true,
    module.exports = function(grunt) { 
    318311                                ]
    319312                        },
    320313                        media: {
    321                                 options: {
    322                                         browserify: true
    323                                 },
    324314                                src: [
    325315                                        SOURCE_DIR + 'wp-includes/js/media/**/*.js'
    326316                                ]
    module.exports = function(grunt) { 
    531521                                dest: SOURCE_DIR + 'wp-includes/js/jquery/jquery.masonry.min.js'
    532522                        }
    533523                },
    534 
     524                webpack: {
     525                        options: {
     526                                stats: ! process.env.NODE_ENV || 'development' === process.env.NODE_ENV
     527                        },
     528                                prod: webpackConfig,
     529                                dev: Object.assign( { watch: true }, webpackConfig )
     530                },
    535531                concat: {
    536532                        tinymce: {
    537533                                options: {
    module.exports = function(grunt) { 
    623619                                }
    624620                        },
    625621                        config: {
    626                                 files: 'Gruntfile.js'
     622                                files: [
     623                                        'Gruntfile.js',
     624                                        'webpack.config.js'
     625                                ]
    627626                        },
    628627                        colors: {
    629628                                files: [SOURCE_DIR + 'wp-admin/css/colors/**'],
    module.exports = function(grunt) { 
    661660
    662661        // Register tasks.
    663662
     663        // Webpack task.
     664        grunt.loadNpmTasks( 'grunt-webpack' );
     665
    664666        // RTL task.
    665667        grunt.registerTask('rtl', ['rtlcss:core', 'rtlcss:colors']);
    666668
    module.exports = function(grunt) { 
    684686        grunt.renameTask( 'watch', '_watch' );
    685687
    686688        grunt.registerTask( 'watch', function() {
    687                 if ( ! this.args.length || this.args.indexOf( 'browserify' ) > -1 ) {
    688                         grunt.config( 'browserify.options', {
    689                                 browserifyOptions: {
    690                                         debug: true
    691                                 },
    692                                 watch: true
    693                         } );
     689                if ( ! this.args.length || this.args.indexOf( 'webpack' ) > -1 ) {
    694690
    695                         grunt.task.run( 'browserify' );
     691                        grunt.task.run( 'webpack' );
    696692                }
    697693
    698694                grunt.task.run( '_' + this.nameArgs );
    module.exports = function(grunt) { 
    703699        ] );
    704700
    705701        grunt.registerTask( 'precommit:js', [
    706                 'browserify',
     702                'webpack',
    707703                'jshint:corejs',
    708704                'uglify:bookmarklet',
    709705                'uglify:masonry',
    module.exports = function(grunt) { 
    768764                                        return regex.test( result.stdout );
    769765                                }
    770766
    771                                 if ( [ 'package.json', 'Gruntfile.js' ].some( testPath ) ) {
     767                                if ( [ 'package.json', 'Gruntfile.js', 'webpack.config.js' ].some( testPath ) ) {
    772768                                        grunt.log.writeln( 'Configuration files modified. Running `prerelease`.' );
    773769                                        taskList.push( 'prerelease' );
    774770                                } else {
    module.exports = function(grunt) { 
    860856        grunt.event.on('watch', function( action, filepath, target ) {
    861857                var src;
    862858
    863                 if ( [ 'all', 'rtl', 'browserify' ].indexOf( target ) === -1 ) {
     859                if ( [ 'all', 'rtl', 'webpack' ].indexOf( target ) === -1 ) {
    864860                        return;
    865861                }
    866862
  • package.json

    diff --git package.json package.json
    index 047d5fc35d..121510b03b 100644
     
    1414  "devDependencies": {
    1515    "autoprefixer": "^6.5.1",
    1616    "grunt": "~0.4.5",
    17     "grunt-browserify": "~5.0.0",
    1817    "grunt-contrib-clean": "~1.0.0",
    1918    "grunt-contrib-compress": "~1.3.0",
    2019    "grunt-contrib-concat": "~1.0.0",
     
    3231    "grunt-postcss": "~0.7.1",
    3332    "grunt-rtlcss": "~2.0.1",
    3433    "grunt-sass": "~1.2.1",
    35     "matchdep": "~1.0.0"
     34    "grunt-webpack": "^3.0.0",
     35    "matchdep": "~1.0.0",
     36    "webpack": "^3.0.0",
     37    "webpack-dev-server": "^2.5.0"
    3638  }
    3739}
  • new file webpack.config.js

    diff --git webpack.config.js webpack.config.js
    new file mode 100644
    index 0000000000..eb7c964d5a
    - +  
     1var path         = require('path'),
     2        SOURCE_DIR   = 'src/',
     3        mediaConfig  = {},
     4        mediaBuilds  = ['audiovideo', 'grid', 'models', 'views'],
     5        webpack      = require('webpack');
     6
     7
     8mediaBuilds.forEach( function ( build ) {
     9        var path = SOURCE_DIR + 'wp-includes/js/media';
     10        mediaConfig[ build ] = './' + path + '/' + build + '.manifest.js';
     11} );
     12
     13module.exports = {
     14        cache: true,
     15        entry: mediaConfig,
     16        output: {
     17                path:     path.join( __dirname, 'src/wp-includes/js' ),
     18                filename: 'media-[name].js'
     19        },
     20        plugins: [
     21                new webpack.optimize.ModuleConcatenationPlugin()
     22        ]
     23}