Permalink
Browse files

two new options: outputbundleonly, bundleminonly

Added two new options and fixed implementation of skipremin option.
Skipremin option would actually not bundle in .min. scripts to the
bundle.min.* file.
outputbundleonly option skips creation of individual .min files for each
file in the bundle - it only outputs the "whole" bundle file.
bundleminonly option skips creation of the non-minimized bundle file,
and only writes the minimized version to disk.
Updated documentation to reflect these new options.
  • Loading branch information...
1 parent af15e68 commit db2a32ca35476a9cabbf8604a54c9bb01062ae33 @isochronous isochronous committed Sep 27, 2012
Showing with 46 additions and 25 deletions.
  1. +3 −1 README.md
  2. +43 −24 src/bundler.js
View
@@ -189,7 +189,9 @@ The currently available options are:
- **nobundle** - Compiles and minifies all files listed, however it does not bundle them into a single file. This allows you to compile and minify your standalone files without concatenating them into a bundle.
- **skipmin** - Skips the minimization step for every file
- **skipremin** - Skips the minification step for files that already contain a '.min.' or '.pack.' in their filename. This lowers the chance of multiple minification iterations introducing problems.
- - **folder** - Used a trigger to transform all files in the folder with this bundle file. If the `recursive` value is used, a seek will search recursively from this root transforming all files in all folders searched. When the `folder` option is used, the `nobundle` option is automatically set. When the `folder` option is used, listing files in the bundle file does nothing.
+ - **folder** - Used as a trigger to transform all files in the folder with this bundle file. If the `recursive` value is used, a seek will search recursively from this root transforming all files in all folders searched. When the `folder` option is used, the `nobundle` option is automatically set. When the `folder` option is used, listing files in the bundle file does nothing.
+ - **outputbundleonly** - Does not create individual .min files for each file in the bundle. The bundled file is the only output.
+ - **bundleminonly** - Does not create a non-minimized version of the bundle file. Only creates the .min version of the bundle.
Tip: If you just want bundler to transform all the files in your content folder, add a bundle file in the root of the content folder and set its contents to the following:
View
@@ -235,7 +235,11 @@ function processJsBundle(options, jsBundle, bundleDir, jsFiles, bundleName, cb)
var minFileName = getMinFileName(bundleName);
fs.writeFile(minFileName, allMinJs, cb);
};
- fs.writeFile(bundleName, allJs, afterBundle);
+ if (!options.bundleminonly) {
+ fs.writeFile(bundleName, allJs, afterBundle);
+ } else {
+ afterBundle();
+ }
};
jsFiles.forEach(function (file) {
@@ -260,7 +264,7 @@ function processJsBundle(options, jsBundle, bundleDir, jsFiles, bundleName, cb)
var next = this;
if (isCoffee) {
readTextFile(filePath, function (coffee) {
- getOrCreateJs(coffee, filePath, jsPath, next);
+ getOrCreateJs(options, coffee, filePath, jsPath, next);
});
} else {
readTextFile(jsPath, next);
@@ -270,12 +274,15 @@ function processJsBundle(options, jsBundle, bundleDir, jsFiles, bundleName, cb)
allJsArr[i] = js;
var withMin = function (minJs) {
allMinJsArr[i] = minJs;
+
if (! --pending) whenDone();
};
- if (options.skipmin || (/(\.min\.|\.pack\.)/.test(file) && options.skipremin)) {
+ if (options.skipmin) {
withMin('');
- } else {
- getOrCreateMinJs(js, jsPath, minJsPath, withMin);
+ } else if (/(\.min\.|\.pack\.)/.test(file) && options.skipremin) {
+ readTextFile(jsPath, withMin);
+ } else {
+ getOrCreateMinJs(options, js, jsPath, minJsPath, withMin);
}
}
);
@@ -307,7 +314,12 @@ function processCssBundle(options, cssBundle, bundleDir, cssFiles, bundleName, c
var minFileName = getMinFileName(bundleName);
fs.writeFile(minFileName, allMinCss, cb);
};
- fs.writeFile(bundleName, allCss, afterBundle);
+
+ if (!options.bundleminonly) {
+ fs.writeFile(bundleName, allCss, afterBundle);
+ } else {
+ afterBundle();
+ }
};
cssFiles.forEach(function (file) {
@@ -334,11 +346,11 @@ function processCssBundle(options, cssBundle, bundleDir, cssFiles, bundleName, c
var next = this;
if (isLess) {
readTextFile(filePath, function (lessText) {
- getOrCreateLessCss(lessText, filePath, cssPath, next);
+ getOrCreateLessCss(options, lessText, filePath, cssPath, next);
});
} else if (isSass) {
readTextFile(filePath, function (sassText) {
- getOrCreateSassCss(sassText, filePath, cssPath, next);
+ getOrCreateSassCss(options, sassText, filePath, cssPath, next);
});
} else {
readTextFile(cssPath, next);
@@ -348,47 +360,50 @@ function processCssBundle(options, cssBundle, bundleDir, cssFiles, bundleName, c
allCssArr[i] = css;
var withMin = function (minCss) {
allMinCssArr[i] = minCss;
+
if (! --pending) whenDone();
};
- if (options.skipmin || (/(\.min\.|\.pack\.)/.test(file) && options.skipremin)) {
+ if (options.skipmin) {
withMin('');
- } else {
- getOrCreateMinCss(css, cssPath, minCssPath, withMin);
+ } else if (/(\.min\.|\.pack\.)/.test(file) && options.skipremin) {
+ readTextFile(cssPath, withMin);
+ }else {
+ getOrCreateMinCss(options, css, cssPath, minCssPath, withMin);
}
}
);
});
}
-function getOrCreateJs(coffeeScript, csPath, jsPath, cb /*cb(js)*/) {
- compileAsync("compiling", function (coffeeScript, csPath, cb) {
+function getOrCreateJs(options, coffeeScript, csPath, jsPath, cb /*cb(js)*/) {
+ compileAsync(options, "compiling", function (coffeeScript, csPath, cb) {
cb(coffee.compile(coffeeScript));
}, coffeeScript, csPath, jsPath, cb);
}
-function getOrCreateMinJs(js, jsPath, minJsPath, cb /*cb(minJs)*/) {
- compileAsync("minifying", function (js, jsPath, cb) {
+function getOrCreateMinJs(options, js, jsPath, minJsPath, cb /*cb(minJs)*/) {
+ compileAsync(options, "minifying", function (js, jsPath, cb) {
cb(minifyjs(js));
}, js, jsPath, minJsPath, cb);
}
-function getOrCreateLessCss(less, lessPath, cssPath, cb /*cb(css)*/) {
- compileAsync("compiling", compileLess, less, lessPath, cssPath, cb);
+function getOrCreateLessCss(options, less, lessPath, cssPath, cb /*cb(css)*/) {
+ compileAsync(options, "compiling", compileLess, less, lessPath, cssPath, cb);
}
-function getOrCreateSassCss(sassText, sassPath, cssPath, cb /*cb(sass)*/) {
- compileAsync("compiling", function (sassText, sassPath, cb) {
+function getOrCreateSassCss(options, sassText, sassPath, cssPath, cb /*cb(sass)*/) {
+ compileAsync(options, "compiling", function (sassText, sassPath, cb) {
cb(sass.render(removeCR(sassText), { options: path.basename(sassPath) }));
}, sassText, sassPath, cssPath, cb);
}
-function getOrCreateMinCss(css, cssPath, minCssPath, cb /*cb(minCss)*/) {
- compileAsync("minifying", function (css, cssPath, cb) {
+function getOrCreateMinCss(options, css, cssPath, minCssPath, cb /*cb(minCss)*/) {
+ compileAsync(options, "minifying", function (css, cssPath, cb) {
cb(cleanCss.process(css));
}, css, cssPath, minCssPath, cb);
}
-function compileAsync(mode, compileFn /*compileFn(text, textPath, cb(compiledText))*/,
+function compileAsync(options, mode, compileFn /*compileFn(text, textPath, cb(compiledText))*/,
text, textPath, compileTextPath, cb /*cb(compiledText)*/) {
Step(
function () {
@@ -409,9 +424,13 @@ function compileAsync(mode, compileFn /*compileFn(text, textPath, cb(compiledTex
if (doCompile) {
console.log(mode + " " + compileTextPath + "...");
var onAfterCompiled = function(minText) {
- fs.writeFile(compileTextPath, minText, 'utf-8', function(_) {
+ if (options.outputbundleonly) {
cb(minText);
- });
+ } else {
+ fs.writeFile(compileTextPath, minText, 'utf-8', function(_) {
+ cb(minText);
+ });
+ }
};
compileFn(text, textPath, onAfterCompiled);
} else {

0 comments on commit db2a32c

Please sign in to comment.