Skip to content

Instantly share code, notes, and snippets.

@hamaluik
Created October 27, 2015 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamaluik/927445db8af221575d89 to your computer and use it in GitHub Desktop.
Save hamaluik/927445db8af221575d89 to your computer and use it in GitHub Desktop.
Flow hook to minify the resulting javascript code (stores it in {{app.name}}.min.js).
// ./hooks/minify.js
var UglifyJS = require("uglify-js"); // run "npm install uglify-js" in the hooks directory first!
var fs = require('fs');
exports.hook = function(flow, done) {
var basePath = flow.project.project.app.output + '/web/' + flow.project.project.app.name;
var result = UglifyJS.minify(basePath + '.js', {
mangle: true // set to false if you run into issues
});
fs.writeFile(basePath + '.min.js', result.code, function(err) {
if(err) console.log(err);
done();
})
}
// ./project.flow
{
project: {
// ...
build: {
// ...
post: {
priority: 1,
name: 'minify',
desc: 'minify the resulting javascript using uglifyjs',
script: './hooks/minify.js'
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment