diff --git Gruntfile.js Gruntfile.js
index c7e7f73b2b..7328a68253 100644
|
|
|
1 | 1 | /* jshint node:true */ |
| 2 | const webpackConfig = require( './webpack.config' ); |
| 3 | |
2 | 4 | module.exports = function(grunt) { |
3 | 5 | var path = require('path'), |
4 | 6 | fs = require( 'fs' ), |
5 | 7 | SOURCE_DIR = 'src/', |
6 | 8 | BUILD_DIR = 'build/', |
7 | | autoprefixer = require('autoprefixer'), |
8 | | mediaConfig = {}, |
9 | | mediaBuilds = ['audiovideo', 'grid', 'models', 'views']; |
| 9 | autoprefixer = require( 'autoprefixer' ); |
10 | 10 | |
11 | 11 | // Load tasks. |
12 | 12 | require('matchdep').filterDev(['grunt-*', '!grunt-legacy-util']).forEach( grunt.loadNpmTasks ); |
13 | 13 | // Load legacy utils |
14 | 14 | grunt.util = require('grunt-legacy-util'); |
15 | 15 | |
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 | | |
22 | 16 | // Project configuration. |
23 | 17 | grunt.initConfig({ |
24 | 18 | postcss: { |
… |
… |
module.exports = function(grunt) { |
157 | 151 | } |
158 | 152 | } |
159 | 153 | }, |
160 | | browserify: mediaConfig, |
161 | 154 | sass: { |
162 | 155 | colors: { |
163 | 156 | expand: true, |
… |
… |
module.exports = function(grunt) { |
318 | 311 | ] |
319 | 312 | }, |
320 | 313 | media: { |
321 | | options: { |
322 | | browserify: true |
323 | | }, |
324 | 314 | src: [ |
325 | 315 | SOURCE_DIR + 'wp-includes/js/media/**/*.js' |
326 | 316 | ] |
… |
… |
module.exports = function(grunt) { |
531 | 521 | dest: SOURCE_DIR + 'wp-includes/js/jquery/jquery.masonry.min.js' |
532 | 522 | } |
533 | 523 | }, |
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 | }, |
535 | 531 | concat: { |
536 | 532 | tinymce: { |
537 | 533 | options: { |
… |
… |
module.exports = function(grunt) { |
623 | 619 | } |
624 | 620 | }, |
625 | 621 | config: { |
626 | | files: 'Gruntfile.js' |
| 622 | files: [ |
| 623 | 'Gruntfile.js', |
| 624 | 'webpack.config.js' |
| 625 | ] |
627 | 626 | }, |
628 | 627 | colors: { |
629 | 628 | files: [SOURCE_DIR + 'wp-admin/css/colors/**'], |
… |
… |
module.exports = function(grunt) { |
661 | 660 | |
662 | 661 | // Register tasks. |
663 | 662 | |
| 663 | // Webpack task. |
| 664 | grunt.loadNpmTasks( 'grunt-webpack' ); |
| 665 | |
664 | 666 | // RTL task. |
665 | 667 | grunt.registerTask('rtl', ['rtlcss:core', 'rtlcss:colors']); |
666 | 668 | |
… |
… |
module.exports = function(grunt) { |
684 | 686 | grunt.renameTask( 'watch', '_watch' ); |
685 | 687 | |
686 | 688 | 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 ) { |
694 | 690 | |
695 | | grunt.task.run( 'browserify' ); |
| 691 | grunt.task.run( 'webpack' ); |
696 | 692 | } |
697 | 693 | |
698 | 694 | grunt.task.run( '_' + this.nameArgs ); |
… |
… |
module.exports = function(grunt) { |
703 | 699 | ] ); |
704 | 700 | |
705 | 701 | grunt.registerTask( 'precommit:js', [ |
706 | | 'browserify', |
| 702 | 'webpack', |
707 | 703 | 'jshint:corejs', |
708 | 704 | 'uglify:bookmarklet', |
709 | 705 | 'uglify:masonry', |
… |
… |
module.exports = function(grunt) { |
768 | 764 | return regex.test( result.stdout ); |
769 | 765 | } |
770 | 766 | |
771 | | if ( [ 'package.json', 'Gruntfile.js' ].some( testPath ) ) { |
| 767 | if ( [ 'package.json', 'Gruntfile.js', 'webpack.config.js' ].some( testPath ) ) { |
772 | 768 | grunt.log.writeln( 'Configuration files modified. Running `prerelease`.' ); |
773 | 769 | taskList.push( 'prerelease' ); |
774 | 770 | } else { |
… |
… |
module.exports = function(grunt) { |
860 | 856 | grunt.event.on('watch', function( action, filepath, target ) { |
861 | 857 | var src; |
862 | 858 | |
863 | | if ( [ 'all', 'rtl', 'browserify' ].indexOf( target ) === -1 ) { |
| 859 | if ( [ 'all', 'rtl', 'webpack' ].indexOf( target ) === -1 ) { |
864 | 860 | return; |
865 | 861 | } |
866 | 862 | |
diff --git package.json package.json
index 047d5fc35d..121510b03b 100644
|
|
|
14 | 14 | "devDependencies": { |
15 | 15 | "autoprefixer": "^6.5.1", |
16 | 16 | "grunt": "~0.4.5", |
17 | | "grunt-browserify": "~5.0.0", |
18 | 17 | "grunt-contrib-clean": "~1.0.0", |
19 | 18 | "grunt-contrib-compress": "~1.3.0", |
20 | 19 | "grunt-contrib-concat": "~1.0.0", |
… |
… |
|
32 | 31 | "grunt-postcss": "~0.7.1", |
33 | 32 | "grunt-rtlcss": "~2.0.1", |
34 | 33 | "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" |
36 | 38 | } |
37 | 39 | } |
diff --git webpack.config.js webpack.config.js
new file mode 100644
index 0000000000..eb7c964d5a
-
|
+
|
|
| 1 | var path = require('path'), |
| 2 | SOURCE_DIR = 'src/', |
| 3 | mediaConfig = {}, |
| 4 | mediaBuilds = ['audiovideo', 'grid', 'models', 'views'], |
| 5 | webpack = require('webpack'); |
| 6 | |
| 7 | |
| 8 | mediaBuilds.forEach( function ( build ) { |
| 9 | var path = SOURCE_DIR + 'wp-includes/js/media'; |
| 10 | mediaConfig[ build ] = './' + path + '/' + build + '.manifest.js'; |
| 11 | } ); |
| 12 | |
| 13 | module.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 | } |