Skip to content

Commit

Permalink
added simplified config option
Browse files Browse the repository at this point in the history
  • Loading branch information
generalhenry committed Feb 4, 2015
1 parent c39d083 commit a5a1ae3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 19 deletions.
29 changes: 12 additions & 17 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@ module.exports = function(grunt) {
grunt.initConfig({
minifyify: {
test: {
files: [{
ignore: ['grunt', 'grunt-cli'],
exclude: ['browserify', 'minifyify'],
external: 'chalk',
require: 'async',
add: './hello-world.js',
dest: {
buildFile: 'tmp/hello-world.min.js',
mapFile: 'tmp/hello-world.min.json',
},
minifyifyOptions: {
map: 'hello-world.min.json'
},
browserifyOptions: {
basedir: 'test/fixtures'
}
}]
inputFolder: 'test/fixtures',
entryFile: 'hello-world',
name: 'hello-world'
},
options: {
ignore: ['grunt', 'grunt-cli'],
exclude: ['browserify', 'minifyify'],
external: 'chalk',
require: 'async',
minifiedExt: '.min.js',
mapExt: '.min.json',
outputFolder: 'tmp'
}
}
});
Expand Down
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<meta charset='utf-8'>
<title>hello world</title>
<script src='tmp/hello-world.min.js'></script>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Grunt plugin to produce minified source and source maps with browserify and minifyify.",
"main": "tasks/minifyify.js",
"scripts": {
"test": "grunt minifyify && mocha"
"test": "rm -rf tmp && grunt minifyify && mocha"
},
"keywords": [
"grunt",
Expand Down
35 changes: 35 additions & 0 deletions tasks/minifyify.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var fs = require('fs');
var path = require('path');
var _ = require('underscore');
var async = require('async');
var chalk = require('chalk');
Expand All @@ -10,6 +11,40 @@ module.exports = function (grunt) {
'minifyify',
'Produces minified bundles with source maps.',
function() {
console.log('yolo', this.options());
var options = this.options({});
var data = this.data;
var minifiedExt = data.minifiedExt || options.minifiedExt;
var mapExt = data.mapExt || options.mapExt;
var inputFolder = data.inputFolder || options.inputFolder;
var outputFolder = data.outputFolder || options.outputFolder;
if (data.name) {
var file = {};
[
'browserifyOptions',
'minifyifyOptions'
].forEach(function (name) {
file[name] = _.extend({}, data[name], options[name]);
});
[
'ignore',
'exclude',
'external',
'require',
'add'
].forEach(function (type) {
file[type] = [].concat(data[type] || []).concat(options[type] || []);
});
file.add.push('./' + path.join(inputFolder, data.entryFile || data.name) + '.js');
file.minifyifyOptions.map = data.name + mapExt;
file.minifyifyOptions.compressPath = outputFolder;
file.dest = {
buildFile: path.join(outputFolder, data.name) + minifiedExt,
mapFile: path.join(outputFolder, data.name) + mapExt
};
console.log(file);
this.files.push(file);
}
async.eachSeries(this.files, function(file, done) {
var bundler = new browserify(_.extend({
debug: true
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/hello-world.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = function() {
module.exports = global.hello = function() {
return 'hello world';
};

0 comments on commit a5a1ae3

Please sign in to comment.