gulp-usemin
Advanced tools
Comparing version 0.1.4 to 0.2.0
69
index.js
@@ -5,5 +5,2 @@ var path = require('path'); | ||
var CleanCSS = require('clean-css'); | ||
var uglify = require('uglify-js'); | ||
var htmlmin = require('minimize'); | ||
var through = require('through2'); | ||
@@ -13,6 +10,3 @@ var gutil = require('gulp-util'); | ||
module.exports = function (options) { | ||
options = options || {}; | ||
options.jsmin = options.jsmin !== false; | ||
options.cssmin = options.cssmin !== false; | ||
options.htmlmin = options.htmlmin !== false; | ||
options = options || {}; // cssmin, htmlmin, jsmin | ||
@@ -24,2 +18,3 @@ var startReg = /<!--\s*build:(css|js)(?:\(([^\)]+)\))?\s+(\/?([^\s]+))\s*-->/gim; | ||
var mainPath, mainName, alternatePath; | ||
var filesCount = 0; | ||
@@ -49,23 +44,20 @@ function createFile(name, content) { | ||
function processJs(content, name) { | ||
var str = concat(content, jsReg, ';' + EOL + EOL); | ||
function write(files, processor, callback) { | ||
if (processor) { | ||
var stream = processor; | ||
stream.on('data', callback); | ||
if (options.jsmin) | ||
str = uglify.minify(str, {fromString: true}).code; | ||
return createFile(name, str); | ||
files.forEach(function(file) { | ||
stream.write(file); | ||
}); | ||
stream.end(); | ||
} | ||
else | ||
files.forEach(callback); | ||
} | ||
function processCss(content, name) { | ||
var str = concat(content, cssReg, EOL + EOL); | ||
if (options.cssmin) | ||
str = new CleanCSS({root: mainPath}).minify(str); | ||
return createFile(name, str); | ||
} | ||
function processHtml(content, callback) { | ||
var html = []; | ||
var files = []; | ||
var jsFiles = []; | ||
var cssFiles = []; | ||
var sections = content.split(endReg); | ||
@@ -82,7 +74,9 @@ | ||
html.push('<script src="' + section[3] + '"></script>'); | ||
files.push(processJs(section[5], section[4])); | ||
jsFiles.push(createFile(section[4], concat(section[5], jsReg, ';' + EOL + EOL))); | ||
filesCount++; | ||
} | ||
else { | ||
html.push('<link rel="stylesheet" href="' + section[3] + '"/>'); | ||
files.push(processCss(section[5], section[4])); | ||
cssFiles.push(createFile(section[4], concat(section[5], cssReg, EOL + EOL))); | ||
filesCount++; | ||
} | ||
@@ -93,13 +87,5 @@ } | ||
if (options.htmlmin) | ||
new htmlmin().parse(html.join(''), function(err, data) { | ||
files.push(createFile(mainName, data)); | ||
callback(files); | ||
}); | ||
else { | ||
files.push(createFile(mainName, html.join(''))); | ||
callback(files); | ||
} | ||
write(jsFiles, options.jsmin, callback); | ||
write(cssFiles, options.cssmin, callback); | ||
write([createFile(mainName, html.join(''))], options.htmlmin, callback); | ||
} | ||
@@ -120,6 +106,9 @@ | ||
processHtml(String(file.contents), function(files) { | ||
for (var i = 0; i < files.length; ++ i) | ||
this.push(files[i]); | ||
callback(); | ||
filesCount = 1; | ||
processHtml(String(file.contents), function(file) { | ||
this.push(file); | ||
filesCount--; | ||
if (filesCount <= 0) | ||
callback(); | ||
}.bind(this)); | ||
@@ -126,0 +115,0 @@ } |
{ | ||
"name": "gulp-usemin", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"description": "Replaces references to non-optimized scripts or stylesheets into a set of HTML files (or any templates/views).", | ||
"main": "index.js", | ||
"dependencies": { | ||
"clean-css": "latest", | ||
"gulp-util": "latest", | ||
"minimize": "latest", | ||
"through2": "latest", | ||
"uglify-js": "latest" | ||
"through2": "latest" | ||
}, | ||
@@ -18,3 +15,6 @@ "devDependencies": { | ||
"gulp-mocha": "latest", | ||
"gulp-util": "latest" | ||
"gulp-util": "latest", | ||
"gulp-uglify": "latest", | ||
"gulp-minify-html": "latest", | ||
"gulp-minify-css": "latest" | ||
}, | ||
@@ -21,0 +21,0 @@ "scripts": { |
@@ -5,2 +5,3 @@ # gulp-usemin | ||
This task is designed for gulp 3. | ||
> Attention: v0.2.0 dont minify files by default. | ||
@@ -19,2 +20,5 @@ ## Usage | ||
var usemin = require('gulp-usemin'); | ||
var uglify = require('gulp-uglify'); | ||
var minifyHtml = require('gulp-minify-html'); | ||
var minifyCss = require('gulp-minify-css'); | ||
@@ -24,5 +28,5 @@ gulp.task('usemin', function() { | ||
.pipe(usemin({ | ||
cssmin: false, | ||
htmlmin: false, | ||
jsmin: false | ||
cssmin: minifyCss(), | ||
htmlmin: minifyHtml(), | ||
jsmin: uglify() | ||
})) | ||
@@ -67,18 +71,15 @@ .pipe(gulp.dest('build/')); | ||
#### cssmin | ||
Type: `Boolean` | ||
Default: `true` | ||
Type: `Object` | ||
If true, minify output css. | ||
Plugin for minify output css. | ||
#### htmlmin | ||
Type: `Boolean` | ||
Default: `true` | ||
Type: `Object` | ||
If true, minify output html. | ||
Plugin for minify output html. | ||
#### jsmin | ||
Type: `Boolean` | ||
Default: `true` | ||
Type: `Object` | ||
If true, minify output js. | ||
Plugin for minify output js. | ||
@@ -121,3 +122,3 @@ | ||
gulp.src('./app/index.html') | ||
.pipe(usemin()) | ||
.pipe(usemin({jsmin: uglify()})) | ||
.pipe(gulp.dest('dist/')); | ||
@@ -124,0 +125,0 @@ }); |
@@ -14,2 +14,5 @@ /* jshint node: true */ | ||
var jsmin = require('gulp-uglify'); | ||
var htmlmin = require('gulp-minify-html'); | ||
var cssmin = require('gulp-minify-css'); | ||
@@ -80,3 +83,3 @@ function getFile(filePath) { | ||
function compare(name, expectedName, done) { | ||
var stream = usemin(); | ||
var stream = usemin({htmlmin: htmlmin({empty: true})}); | ||
@@ -122,5 +125,3 @@ stream.on('data', function(newFile) { | ||
function compare(name, expectedName, done) { | ||
var stream = usemin({ | ||
htmlmin: false | ||
}); | ||
var stream = usemin(); | ||
@@ -166,3 +167,3 @@ stream.on('data', function(newFile) { | ||
function compare(name, callback, end) { | ||
var stream = usemin(); | ||
var stream = usemin({cssmin: cssmin()}); | ||
@@ -239,5 +240,3 @@ stream.on('data', callback); | ||
function compare(name, callback, end) { | ||
var stream = usemin({ | ||
cssmin: false | ||
}); | ||
var stream = usemin(); | ||
@@ -311,3 +310,3 @@ stream.on('data', callback); | ||
function compare(name, callback, end) { | ||
var stream = usemin(); | ||
var stream = usemin({jsmin: jsmin()}); | ||
@@ -384,5 +383,3 @@ stream.on('data', callback); | ||
function compare(name, callback, end) { | ||
var stream = usemin({ | ||
jsmin: false | ||
}); | ||
var stream = usemin(); | ||
@@ -389,0 +386,0 @@ stream.on('data', callback); |
2
146
21791
8
497
- Removedclean-css@latest
- Removedminimize@latest
- Removeduglify-js@latest
- Removedargh@0.1.4(transitive)
- Removedasync@2.6.4(transitive)
- Removedclean-css@5.3.3(transitive)
- Removedcli-color@1.4.0(transitive)
- Removedcolor@3.2.1(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcolor-string@1.9.1(transitive)
- Removedcolornames@1.1.1(transitive)
- Removedcolorspace@1.1.4(transitive)
- Removedd@1.0.2(transitive)
- Removeddiagnostics@1.1.1(transitive)
- Removeddom-serializer@0.2.2(transitive)
- Removeddomelementtype@1.3.12.3.0(transitive)
- Removeddomhandler@2.4.2(transitive)
- Removeddomutils@1.7.0(transitive)
- Removedemits@3.0.0(transitive)
- Removedenabled@1.0.2(transitive)
- Removedentities@1.1.22.2.0(transitive)
- Removedenv-variable@0.0.6(transitive)
- Removedes5-ext@0.10.64(transitive)
- Removedes6-iterator@2.0.3(transitive)
- Removedes6-symbol@3.1.4(transitive)
- Removedes6-weak-map@2.0.3(transitive)
- Removedesniff@2.0.1(transitive)
- Removedevent-emitter@0.3.5(transitive)
- Removedext@1.7.0(transitive)
- Removedhtmlparser2@3.10.1(transitive)
- Removedis-arrayish@0.3.2(transitive)
- Removedis-promise@2.2.2(transitive)
- Removedkuler@1.0.1(transitive)
- Removedlodash@4.17.21(transitive)
- Removedlru-queue@0.1.0(transitive)
- Removedmemoizee@0.4.17(transitive)
- Removedminimize@2.2.0(transitive)
- Removednext-tick@1.1.0(transitive)
- Removedsimple-swizzle@0.2.2(transitive)
- Removedsource-map@0.6.1(transitive)
- Removedtext-hex@1.0.0(transitive)
- Removedtimers-ext@0.1.8(transitive)
- Removedtype@2.7.3(transitive)
- Removeduglify-js@3.19.3(transitive)
- Removeduuid@3.4.0(transitive)