The following will minify your assets with grunt each time a generation write completes.
-
Install Dependencies
npm install grunt safeps --save npm install grunt-cli -g
-
Create your website's grunt file to specify what we should minify. Guide here.
-
Add the following to your docpad configuration file
events: # Write After # Used to minify our assets with grunt writeAfter: (opts,next) -> # Prepare safeps = require('safeps') pathUtil = require('path') docpad = @docpad rootPath = docpad.getConfig().rootPath gruntPath = pathUtil.join(rootPath, 'node_modules', '.bin', 'grunt') # Perform the grunt `min` task # https://github.com/gruntjs/grunt/blob/0.3-stable/docs/task_min.md command = [gruntPath, 'min'] # Execute safeps.spawn(command, {cwd:rootPath,output:true}, next) # Chain @
I was only able to get this working with the
grunt-contrib-uglify
package, like so:First by installing the package:
Then by adding the following to my Gruntfile.js:
Then setting up the following in docpad.coffee: