Dependencies
grunt.loadNpmTasks('grunt-aws');
grunt.loadNpmTasks('grunt-contrib-compress');
Commands
grunt build
grunt compress #gzip assets
grunt s3 #upload to s3
<?php | |
/* remember, we can load JSON in PHP too */ | |
$vf = fopen(dirname(__FILE__) . '/version.json',"r"); | |
$v = json_decode(fread($vf,filesize(dirname(__FILE__) . '/version.json'))); | |
fclose($vf); | |
$cssVer = $v->cssVer; | |
$jsVer = $v->jsVer; | |
?> |
/* manually compress front end assets with gzip for s3 */ | |
initConfig.compress = { | |
css: { | |
options: { | |
mode: 'gzip' | |
}, | |
src: ['<%= dirs.theme %><%= dirs.assets %><%= dirs.css %>main.min.css'], | |
dest: '<%= dirs.theme %><%= dirs.assets %><%= dirs.css %>main.min.' + (grunt.option('cssVer')) + '.cssgz' | |
}, | |
js: { | |
options: { | |
mode: 'gzip' | |
}, | |
src: ['<%= dirs.theme %><%= dirs.assets %><%= dirs.js %>main-min.js'], | |
dest: '<%= dirs.theme %><%= dirs.assets %><%= dirs.js %>main-min.' + (grunt.option('jsVer')) + '.jsgz' | |
} | |
}; | |
if(doS3) { | |
/* upload our gzipped CSS and JS zip files to S3 with appropriate headers */ | |
initConfig.aws = grunt.file.readJSON('aws-secret.json'); | |
initConfig.s3 = { | |
options: { | |
accessKeyId: "<%= aws.accessKeyId %>", | |
secretAccessKey: "<%= aws.secretAccessKey %>", | |
bucket: "markuptips" | |
}, | |
cssgz: { | |
cwd:'<%= dirs.theme %><%= dirs.assets %><%= dirs.css %>', | |
src:'main.min.' + (grunt.option('cssVer')) + '.cssgz', | |
dest:'<%= dirs.assets %><%= dirs.css %>', | |
options:{ | |
gzip:false, // did it ourselves | |
headers:{ | |
ContentType:'text/css', | |
CacheControl:31556926, | |
Expires: new Date(new Date().setYear(new Date().getFullYear() + 1)), | |
ContentEncoding:'gzip' | |
} | |
} | |
}, | |
jsgz: { | |
cwd:'<%= dirs.theme %><%= dirs.assets %><%= dirs.js %>', | |
src:'main-min.' + (grunt.option('jsVer')) + '.jsgz', | |
dest:'<%= dirs.assets %><%= dirs.js %>', | |
options:{ | |
gzip:false, // did it ourselves | |
headers:{ | |
ContentType:'application/javascript', | |
CacheControl:31556926, | |
Expires: new Date(new Date().setYear(new Date().getFullYear() + 1)), | |
ContentEncoding:'gzip' | |
} | |
} | |
} | |
} | |
} |
Example
version.json
Example
aws-secret.json