Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-usemin

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-usemin - npm Package Compare versions

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);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc