description and source-codegulp-minify = function (opt) {
var options = opt || {},
ext = parseExt(options.ext);
options.output = options.output || {};
function minify(file, encoding, callback) {
if (file.isNull()) {
this.push(file);
return callback();
}
if (file.isStream()) {
this.emit('end');
return new callback(PluginError('gulp-minify', 'Streaming not supported:' + file.path));
}
var ignore = false;
if (options.exclude) {
ignore = options.exclude.some(function(item) {
return path.dirname(file.path).split(pathSeparatorRe).some(function(pathName) {
return minimatch(pathName, item);
});
});
}
if (!ignore && options.ignoreFiles) {
ignore = options.ignoreFiles.some(function(item) {
return minimatch(path.basename(file.path), item);
});
}
if (ignore || path.extname(file.path) != '.js') {
this.push(file);
return callback();
}
var mangled,
originalSourceMap;
if (file.sourceMap) {
options.outSourceMap = file.relative;
if (file.sourceMap.mappings !== '') {
options.inSourceMap = file.sourceMap;
}
originalSourceMap = file.sourceMap;
}
if (options.preserveComments === 'all') {
options.output.comments = true;
} else if (options.preserveComments === 'some') {
options.output.comments = /^!|@preserve|@license|@cc_on/i;
} else if (typeof options.preserveComments === 'function') {
options.output.comments = options.preserveComments;
}
options.fromString = options.hasOwnProperty("fromString") ? options.fromString : true;
var min_file = new gutil.File({
path: Array.isArray(ext.min) ? file.path.replace(ext.min[0], ext.min[1]) : file.path.replace(/\.js$/, ext.min),
base: file.base
});
try {
mangled = uglify.minify(String(file.contents), options);
min_file.contents = new Buffer(mangled.code.replace(reSourceMapComment, ''));
} catch (e) {
this.emit('end');
return callback(new PluginError('gulp-minify', formatError(e, file)));
}
if (file.sourceMap) {
min_file.sourceMap = JSON.parse(mangled.map);
min_file.sourceMap.sourcesContent = originalSourceMap.sourcesContent;
min_file.sourceMap.sources = originalSourceMap.sources;
}
this.push(min_file);
if (!options.noSource) {
file.path = file.path.replace(/\.js$/, ext.src);
this.push(file);
}
callback();
}
return through.obj(minify);
}