Use browserify
's watch mechanism in tandem with grunt watch
. Makes building media bundles about 10 (million) times faster.
Make the `browserify` config more dynamic to make future additions easier and to ensure proper use of `SOURCE_DIR`. Props iseulde, wonderboymusic. See #28510. git-svn-id: https://develop.svn.wordpress.org/trunk@31629 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
67324a9234
commit
06a86d1425
88
Gruntfile.js
88
Gruntfile.js
@ -2,13 +2,21 @@
|
|||||||
module.exports = function(grunt) {
|
module.exports = function(grunt) {
|
||||||
var path = require('path'),
|
var path = require('path'),
|
||||||
SOURCE_DIR = 'src/',
|
SOURCE_DIR = 'src/',
|
||||||
BUILD_DIR = 'build/';
|
BUILD_DIR = 'build/',
|
||||||
|
mediaConfig = {},
|
||||||
|
mediaBuilds = ['audio-video', 'grid', 'models', 'views'];
|
||||||
|
|
||||||
// Load tasks.
|
// Load tasks.
|
||||||
require('matchdep').filterDev(['grunt-*', '!grunt-legacy-util']).forEach( grunt.loadNpmTasks );
|
require('matchdep').filterDev(['grunt-*', '!grunt-legacy-util']).forEach( grunt.loadNpmTasks );
|
||||||
// Load legacy utils
|
// Load legacy utils
|
||||||
grunt.util = require('grunt-legacy-util');
|
grunt.util = require('grunt-legacy-util');
|
||||||
|
|
||||||
|
mediaBuilds.forEach( function ( build ) {
|
||||||
|
var path = SOURCE_DIR + 'wp-includes/js/media/';
|
||||||
|
mediaConfig[ build ] = { files : {} };
|
||||||
|
mediaConfig[ build ].files[ path + build + '.js' ] = [ path + build + '.manifest.js' ];
|
||||||
|
} );
|
||||||
|
|
||||||
// Project configuration.
|
// Project configuration.
|
||||||
grunt.initConfig({
|
grunt.initConfig({
|
||||||
autoprefixer: {
|
autoprefixer: {
|
||||||
@ -116,16 +124,7 @@ module.exports = function(grunt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
browserify: {
|
browserify: mediaConfig,
|
||||||
media: {
|
|
||||||
files: {
|
|
||||||
'src/wp-includes/js/media/models.js' : [ SOURCE_DIR + 'wp-includes/js/media/models.manifest.js' ],
|
|
||||||
'src/wp-includes/js/media/views.js' : [ SOURCE_DIR + 'wp-includes/js/media/views.manifest.js' ],
|
|
||||||
'src/wp-includes/js/media/audio-video.js' : [ SOURCE_DIR + 'wp-includes/js/media/audio-video.manifest.js' ],
|
|
||||||
'src/wp-includes/js/media/grid.js' : [ SOURCE_DIR + 'wp-includes/js/media/grid.manifest.js' ]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
sass: {
|
sass: {
|
||||||
colors: {
|
colors: {
|
||||||
expand: true,
|
expand: true,
|
||||||
@ -502,7 +501,7 @@ module.exports = function(grunt) {
|
|||||||
dest: SOURCE_DIR
|
dest: SOURCE_DIR
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
_watch: {
|
||||||
all: {
|
all: {
|
||||||
files: [
|
files: [
|
||||||
SOURCE_DIR + '**',
|
SOURCE_DIR + '**',
|
||||||
@ -518,13 +517,10 @@ module.exports = function(grunt) {
|
|||||||
},
|
},
|
||||||
browserify: {
|
browserify: {
|
||||||
files: [
|
files: [
|
||||||
SOURCE_DIR + 'wp-includes/js/media/**/*.js',
|
SOURCE_DIR + 'wp-includes/js/media/*.js',
|
||||||
'!' + SOURCE_DIR + 'wp-includes/js/media/audio-video.js',
|
'!' + SOURCE_DIR + 'wp-includes/js/media/*.manifest.js'
|
||||||
'!' + SOURCE_DIR + 'wp-includes/js/media/grid.js',
|
|
||||||
'!' + SOURCE_DIR + 'wp-includes/js/media/models.js',
|
|
||||||
'!' + SOURCE_DIR + 'wp-includes/js/media/views.js'
|
|
||||||
],
|
],
|
||||||
tasks: ['browserify', 'uglify:media']
|
tasks: ['uglify:media']
|
||||||
},
|
},
|
||||||
config: {
|
config: {
|
||||||
files: 'Gruntfile.js'
|
files: 'Gruntfile.js'
|
||||||
@ -571,17 +567,55 @@ module.exports = function(grunt) {
|
|||||||
'jshint:media'
|
'jshint:media'
|
||||||
] );
|
] );
|
||||||
|
|
||||||
// Pre-commit task.
|
grunt.renameTask( 'watch', '_watch' );
|
||||||
grunt.registerTask('precommit', 'Runs front-end dev/test tasks in preparation for a commit.',
|
|
||||||
['autoprefixer:core', 'imagemin:core', 'jshint:corejs', 'qunit:compiled', 'uglify:bookmarklet']);
|
|
||||||
|
|
||||||
// Copy task.
|
grunt.registerTask( 'watch', function() {
|
||||||
grunt.registerTask('copy:all', ['copy:files', 'copy:wp-admin-rtl', 'copy:version']);
|
if ( ! this.args.length || this.args.indexOf( 'browserify' ) > -1 ) {
|
||||||
|
grunt.config( 'browserify.options', {
|
||||||
|
browserifyOptions: {
|
||||||
|
debug: true
|
||||||
|
},
|
||||||
|
watch: true
|
||||||
|
} );
|
||||||
|
|
||||||
// Build task.
|
grunt.task.run( 'browserify' );
|
||||||
grunt.registerTask('build', ['clean:all', 'copy:all', 'cssmin:core', 'colors', 'rtl', 'cssmin:rtl', 'cssmin:colors',
|
}
|
||||||
'browserify:media', 'uglify:core', 'uglify:media', 'uglify:jqueryui', 'concat:tinymce', 'compress:tinymce',
|
|
||||||
'clean:tinymce', 'jsvalidate:build']);
|
grunt.task.run( '_' + this.nameArgs );
|
||||||
|
} );
|
||||||
|
|
||||||
|
grunt.registerTask( 'precommit', 'Runs front-end dev/test tasks in preparation for a commit.', [
|
||||||
|
'autoprefixer:core',
|
||||||
|
'imagemin:core',
|
||||||
|
'browserify',
|
||||||
|
'jshint:corejs',
|
||||||
|
'qunit:compiled',
|
||||||
|
'uglify:bookmarklet'
|
||||||
|
] );
|
||||||
|
|
||||||
|
grunt.registerTask( 'copy:all', [
|
||||||
|
'copy:files',
|
||||||
|
'copy:wp-admin-rtl',
|
||||||
|
'copy:version'
|
||||||
|
] );
|
||||||
|
|
||||||
|
grunt.registerTask( 'build', [
|
||||||
|
'clean:all',
|
||||||
|
'copy:all',
|
||||||
|
'cssmin:core',
|
||||||
|
'colors',
|
||||||
|
'rtl',
|
||||||
|
'cssmin:rtl',
|
||||||
|
'cssmin:colors',
|
||||||
|
'browserify',
|
||||||
|
'uglify:core',
|
||||||
|
'uglify:media',
|
||||||
|
'uglify:jqueryui',
|
||||||
|
'concat:tinymce',
|
||||||
|
'compress:tinymce',
|
||||||
|
'clean:tinymce',
|
||||||
|
'jsvalidate:build'
|
||||||
|
] );
|
||||||
|
|
||||||
// Testing tasks.
|
// Testing tasks.
|
||||||
grunt.registerMultiTask('phpunit', 'Runs PHPUnit tests, including the ajax, external-http, and multisite tests.', function() {
|
grunt.registerMultiTask('phpunit', 'Runs PHPUnit tests, including the ajax, external-http, and multisite tests.', function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user