Skip to content

Commit

Permalink
Add libs, libs2min, void and remove flows
Browse files Browse the repository at this point in the history
`libs`:
Concatinates only. Useful for vendor files if you want them
separately and are using minified versions in developement(why?).

`libs2min`:
Concatenates only BUT transforms the source filename before like so:
path/filename.js -> path/filename.min.js
Useful if you use long versions in dev environment but want to use
minified versions of vendor files in production, have those files
around(bower!) and don't want to mess around minifying them yourself.

`void`:
Does nothing but replaces the block with new reference. Useful if you
have the same block on multiple html files but don't want to concat or
uglify it several times.

`remove`:
Does nothing but removes the block all together. Nothing is left even
not the reference.

Try them out.
  • Loading branch information
rauno56 committed Jan 15, 2014
1 parent 9586c1a commit 11d3990
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
25 changes: 25 additions & 0 deletions lib/config/libs.js
@@ -0,0 +1,25 @@
'use strict';
var path = require('path');

exports.name = 'concat';

//
// Output a config for the furnished block
// The context variable is used both to take the files to be treated
// (inFiles) and to output the one(s) created (outFiles).
// It aslo conveys whether or not the current process is the last of the pipe
//
exports.createConfig = function(context, block) {
var cfg = {files: []};
// FIXME: check context has all the needed info
var outfile = path.join(context.outDir, block.dest);

// Depending whether or not we're the last of the step we're not going to output the same thing
var files = {};
files.dest = outfile;
files.src = [];
context.inFiles.forEach(function(f) { files.src.push(path.join(context.inDir, f));} );
cfg.files.push(files);
context.outFiles = [block.dest];
return cfg;
};
25 changes: 25 additions & 0 deletions lib/config/libs2min.js
@@ -0,0 +1,25 @@
'use strict';
var path = require('path');

exports.name = 'concat';

//
// Output a config for the furnished block
// The context variable is used both to take the files to be treated
// (inFiles) and to output the one(s) created (outFiles).
// It aslo conveys whether or not the current process is the last of the pipe
//
exports.createConfig = function(context, block) {
var cfg = {files: []};
// FIXME: check context has all the needed info
var outfile = path.join(context.outDir, block.dest);

// Depending whether or not we're the last of the step we're not going to output the same thing
var files = {};
files.dest = outfile;
files.src = [];
context.inFiles.forEach(function(f) { files.src.push(path.join(context.inDir, f.replace(/\.js$/, '.min.js')));} );
cfg.files.push(files);
context.outFiles = [block.dest];
return cfg;
};
4 changes: 3 additions & 1 deletion lib/fileprocessor.js
Expand Up @@ -96,8 +96,10 @@ FileProcessor.prototype.replaceWith = function replaceWith(block) {
result = '<link rel="stylesheet" href="' + dest + '"' + media + '/>';
} else if (block.defer) {
result = '<script defer src="' + dest + '"><\/script>';
} else if (~['js', 'libs'].indexOf(block.type)) {
} else if (~['js', 'libs', 'libs2min', 'void'].indexOf(block.type)) {
result = '<script src="' + dest + '"><\/script>';
} else {
result = '';
}
}
return block.indent + conditionalStart + result + conditionalEnd;
Expand Down
9 changes: 8 additions & 1 deletion tasks/usemin.js
Expand Up @@ -11,7 +11,14 @@ var inspect = function (obj) {
// - the default one
var getFlowFromConfig = function(config, target) {
var Flow = require('../lib/flow');
var flow = new Flow({ steps: {'js': ['concat', 'uglifyjs'], 'css': ['concat', 'cssmin']}, post: {}});
var flow = new Flow({ steps: {
'js': ['concat', 'uglifyjs'],
'css': ['concat', 'cssmin'],
'libs2min': ['libs2min'],
'libs': ['libs'],
'remove': [],
'void': []
}, post: {}});
if (config.options && config.options.flow) {
if (config.options.flow[target]) {
flow.setSteps(config.options.flow[target].steps);
Expand Down

0 comments on commit 11d3990

Please sign in to comment.