Replace grunt-wp-assets with grunt-filerev and grunt-filerev-assets

By writing to assets-manifest.json with grunt-filerev-assets, it's
no longer necessary to commit changes to lib/scripts.php when developing
This commit is contained in:
Ben Word
2014-02-21 23:14:12 -06:00
parent 94cc2949a2
commit 5b23b7fb96
4 changed files with 28 additions and 14 deletions

1
.gitignore vendored
View File

@@ -6,3 +6,4 @@ assets/css/main.css.map
assets/css/*main*.css
assets/js/*scripts*.js
assets/js/vendor/modernizr.min.js
assets-manifest.json

View File

@@ -25,8 +25,8 @@ module.exports = function(grunt) {
all: [
'Gruntfile.js',
'assets/js/*.js',
'!assets/js/*.min.js',
'!assets/js/scripts.js'
'!assets/js/scripts.js',
'!assets/**/*.min.*'
]
},
less: {
@@ -72,12 +72,6 @@ module.exports = function(grunt) {
}
}
},
version: {
assets: {
src: ['assets/css/main.min.css', 'assets/js/scripts.min.js'],
dest: 'lib/scripts.php'
}
},
modernizr: {
build: {
devFile: 'assets/vendor/modernizr/modernizr.js',
@@ -92,6 +86,18 @@ module.exports = function(grunt) {
parseFiles: true
}
},
filerev: {
assets: {
src: ['assets/css/main.min.css', 'assets/js/scripts.min.js']
}
},
filerev_assets: {
assets: {
options: {
dest: 'assets-manifest.json'
}
}
},
watch: {
less: {
files: [
@@ -146,7 +152,8 @@ module.exports = function(grunt) {
'less:build',
'uglify',
'modernizr',
'version'
'filerev',
'filerev_assets'
]);
};

View File

@@ -3,18 +3,23 @@
* Enqueue scripts and stylesheets
*
* Enqueue stylesheets in the following order:
* 1. /theme/assets/css/main.3368efd2.min.css
* 1. /theme/assets/css/main.css
*
* Enqueue scripts in the following order:
* 1. jquery-1.11.0.min.js via Google CDN
* 2. /theme/assets/js/vendor/modernizr.min.js
* 3. /theme/assets/js/main.min.js (in footer)
* 3. /theme/assets/js/main.js (in footer)
*/
function roots_scripts() {
// The build task in Grunt renames production assets with a hash
// Read the asset names from assets-manifest.json
$get_assets = file_get_contents(get_template_directory_uri() . '/assets-manifest.json');
$assets = json_decode($get_assets, true);
if (WP_ENV === 'development') {
wp_enqueue_style('roots_main_dev', get_template_directory_uri() . '/assets/css/main.css', false, null);
} else {
wp_enqueue_style('roots_main', get_template_directory_uri() . '/assets/css/main.3368efd2.min.css', false, null);
wp_enqueue_style('roots_main', get_template_directory_uri() . '/' . $assets['assets/css/main.min.css'], false, null);
}
// jQuery is loaded using the same method from HTML5 Boilerplate:
@@ -32,7 +37,7 @@ function roots_scripts() {
wp_register_script('modernizr', get_template_directory_uri() . '/assets/js/vendor/modernizr.min.js', array(), null, false);
wp_register_script('roots_scripts_dev', get_template_directory_uri() . '/assets/js/scripts.js', array(), null, true);
wp_register_script('roots_scripts', get_template_directory_uri() . '/assets/js/scripts.0fc6af96.min.js', array(), null, true);
wp_register_script('roots_scripts', get_template_directory_uri() . '/' . $assets['assets/js/scripts.min.js'], array(), null, true);
wp_enqueue_script('modernizr');
wp_enqueue_script('jquery');
if (WP_ENV === 'development') {

View File

@@ -31,7 +31,8 @@
"grunt-contrib-uglify": "~0.2.4",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-less": "~0.8.1",
"grunt-wp-assets": "~0.2.1",
"grunt-filerev": "~0.2.1",
"grunt-filerev-assets": "~0.3.0",
"grunt-modernizr": "~0.5.1",
"load-grunt-tasks": "~0.3.0"
}