uglifyjs-webpack-plugin
Advanced tools
Comparing version 0.4.6 to 1.0.0-beta.0
@@ -1,78 +0,36 @@ | ||
0.4.3 / 2017-04-15 | ||
================== | ||
# Change Log | ||
* Docs - Document new features. #26 | ||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. | ||
0.4.2 / 2017-04-12 | ||
================== | ||
<a name="1.0.0-beta.0"></a> | ||
# [1.0.0-beta.0](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/compare/v0.1.4...v1.0.0-beta.0) (2017-06-29) | ||
* Chore - Fix readme link formatting. #25 | ||
0.4.1 / 2017-04-05 | ||
================== | ||
### Bug Fixes | ||
* Chore - Note that cheap source maps don't work with the plugin. #22 | ||
* typo "filterd" -> "filtered" ([#37](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/37)) ([238c373](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/commit/238c373)) | ||
* **package:** mv uglify2 to `dependencies` && update `peerDependencies` ([#45](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/45)) ([93b0cd2](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/commit/93b0cd2)) | ||
* **uglify:** use Compress API not ast.transform ([990f2e2](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/commit/990f2e2)) | ||
0.4.0 / 2017-03-30 | ||
================== | ||
* Chore - Update to *webpack-sources* ^0.2.3. #22 | ||
### Code Refactoring | ||
0.3.1 / 2017-03-22 | ||
================== | ||
* apply `webpack-defaults` ([#35](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/35)) ([f6c5aa9](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/commit/f6c5aa9)) | ||
* Chore - Improve readme wording. #19 | ||
0.3.0 / 2017-03-04 | ||
================== | ||
### BREAKING CHANGES | ||
* Chore - Update to UglifyJS 2.8.0 API internally. #16 | ||
* Enforces `peerDependencies` of `"webpack": ">= 3.0.0-rc.0 || ^3.0.0"`. | ||
* Enforces `engines` of `"node": ">=4.3.0 < 5.0.0 || >= 5.10` | ||
0.2.2 / 2017-03-02 | ||
================== | ||
* Bug fix - Fix `postinstall` script. Now it works if you install the packagre from repository in Node 6+. | ||
0.2.1 / 2017-02-20 | ||
================== | ||
<a name="0.4.6"></a> | ||
## [0.4.6](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/compare/v0.1.4...v0.4.6) (2017-06-29) | ||
* Docs - Fix typo at readme. #10 | ||
0.2.0 / 2017-02-19 | ||
================== | ||
### Bug Fixes | ||
* Feature - Allow to extract comments to separate file [webpack/webpack#4134](https://github.com/webpack/webpack/pull/4134) | ||
* Feature - Allow to supress uglifyjs warnings [webpack/webpack#4200](https://github.com/webpack/webpack/pull/4200) | ||
* Chore - Use `const` where applicable [1d78f99](https://github.com/webpack/webpack/commit/1d78f990a6af1a5b85e45b345b4f7861b03bb12b) | ||
* Chore - Avoid reassigning stream with different value [92364dc](https://github.com/webpack/webpack/commit/92364dc0f72ad8c3ac0bdc74e46766658086d83a) | ||
* Chore - Avoid reassigning files with different value [104398f](https://github.com/webpack/webpack/commit/104398f87a707a601427e666ed318d2338e8a003) | ||
0.1.5 / 2017-02-15 | ||
================== | ||
* Docs - Add `extractComments` documentation. #7 | ||
0.1.4 / 2017-02-06 | ||
================== | ||
* Docs - Simplify example. | ||
0.1.3 / 2017-02-02 | ||
================== | ||
* Docs - Fix table syntax. #6 | ||
0.1.2 / 2017-01-25 | ||
================== | ||
* Docs - Add note about the plugin embedded to webpack. | ||
0.1.1 / 2017-01-25 | ||
================== | ||
* Docs - Update installation instructions. | ||
0.1.0 / 2017-01-24 | ||
================== | ||
* Initial port from webpack source. | ||
* typo "filterd" -> "filtered" ([#37](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/37)) ([238c373](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/commit/238c373)) | ||
* **package:** mv uglify2 to `dependencies` && update `peerDependencies` ([#45](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/45)) ([93b0cd2](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/commit/93b0cd2)) | ||
* **uglify:** use Compress API not ast.transform ([990f2e2](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/commit/990f2e2)) |
@@ -1,253 +0,291 @@ | ||
/* | ||
MIT License http://www.opensource.org/licenses/mit-license.php | ||
Author Tobias Koppers @sokra | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /* | ||
MIT License http://www.opensource.org/licenses/mit-license.php | ||
Author Tobias Koppers @sokra | ||
*/ | ||
// TODO: temporarily disabled rules | ||
/* eslint-disable | ||
no-undefined, | ||
no-param-reassign, | ||
no-underscore-dangle, | ||
import/order | ||
*/ | ||
"use strict"; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _sourceMap = require('source-map'); | ||
var _webpackSources = require('webpack-sources'); | ||
var _RequestShortener = require('webpack/lib/RequestShortener'); | ||
var _RequestShortener2 = _interopRequireDefault(_RequestShortener); | ||
var _ModuleFilenameHelpers = require('webpack/lib/ModuleFilenameHelpers'); | ||
var _ModuleFilenameHelpers2 = _interopRequireDefault(_ModuleFilenameHelpers); | ||
var _uglifyJs = require('uglify-js'); | ||
var _uglifyJs2 = _interopRequireDefault(_uglifyJs); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var SourceMapConsumer = require("source-map").SourceMapConsumer; | ||
var SourceMapSource = require("webpack-sources").SourceMapSource; | ||
var RawSource = require("webpack-sources").RawSource; | ||
var ConcatSource = require("webpack-sources").ConcatSource; | ||
var RequestShortener = require("webpack/lib/RequestShortener"); | ||
var ModuleFilenameHelpers = require("webpack/lib/ModuleFilenameHelpers"); | ||
var uglify = require("uglify-js"); | ||
var UglifyJsPlugin = function () { | ||
function UglifyJsPlugin(options) { | ||
_classCallCheck(this, UglifyJsPlugin); | ||
function UglifyJsPlugin(options) { | ||
_classCallCheck(this, UglifyJsPlugin); | ||
if ((typeof options === "undefined" ? "undefined" : _typeof(options)) !== "object" || Array.isArray(options)) options = {}; | ||
if (typeof options.compressor !== "undefined") options.compress = options.compressor; | ||
this.options = options; | ||
} | ||
if (typeof options !== 'object' || Array.isArray(options)) { | ||
options = {}; | ||
} | ||
if (typeof options.compressor !== 'undefined') { | ||
options.compress = options.compressor; | ||
} | ||
_createClass(UglifyJsPlugin, [{ | ||
key: "apply", | ||
value: function apply(compiler) { | ||
var options = this.options; | ||
options.test = options.test || /\.js($|\?)/i; | ||
var warningsFilter = options.warningsFilter || function () { | ||
return true; | ||
}; | ||
this.options = options; | ||
} | ||
var requestShortener = new RequestShortener(compiler.context); | ||
compiler.plugin("compilation", function (compilation) { | ||
if (options.sourceMap) { | ||
compilation.plugin("build-module", function (module) { | ||
// to get detailed location info about errors | ||
module.useSourceMap = true; | ||
}); | ||
} | ||
compilation.plugin("optimize-chunk-assets", function (chunks, callback) { | ||
var files = []; | ||
chunks.forEach(function (chunk) { | ||
return files.push.apply(files, chunk.files); | ||
}); | ||
files.push.apply(files, compilation.additionalChunkAssets); | ||
var filteredFiles = files.filter(ModuleFilenameHelpers.matchObject.bind(undefined, options)); | ||
filteredFiles.forEach(function (file) { | ||
var oldWarnFunction = uglify.AST_Node.warn_function; | ||
var warnings = []; | ||
var sourceMap = void 0; | ||
try { | ||
var asset = compilation.assets[file]; | ||
if (asset.__UglifyJsPlugin) { | ||
compilation.assets[file] = asset.__UglifyJsPlugin; | ||
return; | ||
} | ||
var input = void 0; | ||
var inputSourceMap = void 0; | ||
if (options.sourceMap) { | ||
if (asset.sourceAndMap) { | ||
var sourceAndMap = asset.sourceAndMap(); | ||
inputSourceMap = sourceAndMap.map; | ||
input = sourceAndMap.source; | ||
} else { | ||
inputSourceMap = asset.map(); | ||
input = asset.source(); | ||
} | ||
sourceMap = new SourceMapConsumer(inputSourceMap); | ||
uglify.AST_Node.warn_function = function (warning) { | ||
// eslint-disable-line camelcase | ||
var match = /\[.+:([0-9]+),([0-9]+)\]/.exec(warning); | ||
var line = +match[1]; | ||
var column = +match[2]; | ||
var original = sourceMap.originalPositionFor({ | ||
line: line, | ||
column: column | ||
}); | ||
if (!original || !original.source || original.source === file) return; | ||
if (!warningsFilter(original.source)) return; | ||
warnings.push(warning.replace(/\[.+:([0-9]+),([0-9]+)\]/, "") + "[" + requestShortener.shorten(original.source) + ":" + original.line + "," + original.column + "]"); | ||
}; | ||
} else { | ||
input = asset.source(); | ||
uglify.AST_Node.warn_function = function (warning) { | ||
// eslint-disable-line camelcase | ||
warnings.push(warning); | ||
}; | ||
} | ||
uglify.base54.reset(); | ||
var ast = uglify.parse(input, { | ||
filename: file | ||
}); | ||
if (options.compress !== false) { | ||
ast.figure_out_scope(); | ||
var compress = uglify.Compressor(options.compress || { | ||
warnings: false | ||
}); // eslint-disable-line new-cap | ||
ast = compress.compress(ast); | ||
} | ||
if (options.mangle !== false) { | ||
ast.figure_out_scope(options.mangle || {}); | ||
ast.compute_char_frequency(options.mangle || {}); | ||
ast.mangle_names(options.mangle || {}); | ||
if (options.mangle && options.mangle.props) { | ||
uglify.mangle_properties(ast, options.mangle.props); | ||
} | ||
} | ||
var output = {}; | ||
output.comments = Object.prototype.hasOwnProperty.call(options, "comments") ? options.comments : /^\**!|@preserve|@license/; | ||
output.beautify = options.beautify; | ||
for (var k in options.output) { | ||
output[k] = options.output[k]; | ||
} | ||
var extractedComments = []; | ||
if (options.extractComments) { | ||
var condition = {}; | ||
if (typeof options.extractComments === "string" || options.extractComments instanceof RegExp) { | ||
// extractComments specifies the extract condition and output.comments specifies the preserve condition | ||
condition.preserve = output.comments; | ||
condition.extract = options.extractComments; | ||
} else if (Object.prototype.hasOwnProperty.call(options.extractComments, "condition")) { | ||
// Extract condition is given in extractComments.condition | ||
condition.preserve = output.comments; | ||
condition.extract = options.extractComments.condition; | ||
} else { | ||
// No extract condition is given. Extract comments that match output.comments instead of preserving them | ||
condition.preserve = false; | ||
condition.extract = output.comments; | ||
} | ||
_createClass(UglifyJsPlugin, [{ | ||
key: 'apply', | ||
value: function apply(compiler) { | ||
var options = this.options; | ||
// Ensure that both conditions are functions | ||
["preserve", "extract"].forEach(function (key) { | ||
switch (_typeof(condition[key])) { | ||
case "boolean": | ||
var b = condition[key]; | ||
condition[key] = function () { | ||
return b; | ||
}; | ||
break; | ||
case "function": | ||
break; | ||
case "string": | ||
if (condition[key] === "all") { | ||
condition[key] = function () { | ||
return true; | ||
}; | ||
break; | ||
} | ||
var regex = new RegExp(condition[key]); | ||
condition[key] = function (astNode, comment) { | ||
return regex.test(comment.value); | ||
}; | ||
break; | ||
default: | ||
regex = condition[key]; | ||
condition[key] = function (astNode, comment) { | ||
return regex.test(comment.value); | ||
}; | ||
} | ||
}); | ||
options.test = options.test || /\.js($|\?)/i; | ||
var warningsFilter = options.warningsFilter || function () { | ||
return true; | ||
}; | ||
// Redefine the comments function to extract and preserve | ||
// comments according to the two conditions | ||
output.comments = function (astNode, comment) { | ||
if (condition.extract(astNode, comment)) { | ||
extractedComments.push(comment.type === "comment2" ? "/*" + comment.value + "*/" : "//" + comment.value); | ||
} | ||
return condition.preserve(astNode, comment); | ||
}; | ||
} | ||
var map = void 0; | ||
if (options.sourceMap) { | ||
map = uglify.SourceMap({ // eslint-disable-line new-cap | ||
file: file, | ||
root: "" | ||
}); | ||
output.source_map = map; // eslint-disable-line camelcase | ||
} | ||
var stream = uglify.OutputStream(output); // eslint-disable-line new-cap | ||
ast.print(stream); | ||
if (map) map = map + ""; | ||
var stringifiedStream = stream + ""; | ||
var outputSource = map ? new SourceMapSource(stringifiedStream, file, JSON.parse(map), input, inputSourceMap) : new RawSource(stringifiedStream); | ||
if (extractedComments.length > 0) { | ||
var commentsFile = options.extractComments.filename || file + ".LICENSE"; | ||
if (typeof commentsFile === "function") { | ||
commentsFile = commentsFile(file); | ||
} | ||
var requestShortener = new _RequestShortener2.default(compiler.context); | ||
compiler.plugin('compilation', function (compilation) { | ||
if (options.sourceMap) { | ||
compilation.plugin('build-module', function (module) { | ||
// to get detailed location info about errors | ||
module.useSourceMap = true; | ||
}); | ||
} | ||
compilation.plugin('optimize-chunk-assets', function (chunks, callback) { | ||
var files = []; | ||
// eslint-disable-next-line prefer-spread | ||
chunks.forEach(function (chunk) { | ||
return files.push.apply(files, chunk.files); | ||
}); | ||
// eslint-disable-next-line prefer-spread | ||
files.push.apply(files, compilation.additionalChunkAssets); | ||
var filteredFiles = files.filter(_ModuleFilenameHelpers2.default.matchObject.bind(undefined, options)); | ||
var uglifiedAssets = new WeakSet(); | ||
filteredFiles.forEach(function (file) { | ||
var oldWarnFunction = _uglifyJs2.default.AST_Node.warn_function; | ||
var warnings = []; | ||
var sourceMap = void 0; | ||
try { | ||
var asset = compilation.assets[file]; | ||
if (uglifiedAssets.has(asset)) { | ||
return; | ||
} | ||
var input = void 0; | ||
var inputSourceMap = void 0; | ||
if (options.sourceMap) { | ||
if (asset.sourceAndMap) { | ||
var sourceAndMap = asset.sourceAndMap(); | ||
inputSourceMap = sourceAndMap.map; | ||
input = sourceAndMap.source; | ||
} else { | ||
inputSourceMap = asset.map(); | ||
input = asset.source(); | ||
} | ||
sourceMap = new _sourceMap.SourceMapConsumer(inputSourceMap); | ||
_uglifyJs2.default.AST_Node.warn_function = function (warning) { | ||
// eslint-disable-line camelcase | ||
var match = /\[.+:([0-9]+),([0-9]+)\]/.exec(warning); | ||
var line = +match[1]; | ||
var column = +match[2]; | ||
var original = sourceMap.originalPositionFor({ | ||
line, | ||
column | ||
}); | ||
if (!original || !original.source || original.source === file) return; | ||
if (!warningsFilter(original.source)) return; | ||
warnings.push(`${warning.replace(/\[.+:([0-9]+),([0-9]+)\]/, '')}[${requestShortener.shorten(original.source)}:${original.line},${original.column}]`); | ||
}; | ||
} else { | ||
input = asset.source(); | ||
_uglifyJs2.default.AST_Node.warn_function = function (warning) { | ||
// eslint-disable-line camelcase | ||
warnings.push(warning); | ||
}; | ||
} | ||
_uglifyJs2.default.base54.reset(); | ||
var ast = _uglifyJs2.default.parse(input, { | ||
filename: file | ||
}); | ||
if (options.compress !== false) { | ||
ast.figure_out_scope(); | ||
var compress = _uglifyJs2.default.Compressor(options.compress || { | ||
warnings: false | ||
}); // eslint-disable-line new-cap | ||
ast = compress.compress(ast); | ||
} | ||
if (options.mangle !== false) { | ||
ast.figure_out_scope(options.mangle || {}); | ||
ast.compute_char_frequency(options.mangle || {}); | ||
ast.mangle_names(options.mangle || {}); | ||
if (options.mangle && options.mangle.props) { | ||
_uglifyJs2.default.mangle_properties(ast, options.mangle.props); | ||
} | ||
} | ||
var output = {}; | ||
output.comments = Object.prototype.hasOwnProperty.call(options, 'comments') ? options.comments : /^\**!|@preserve|@license/; | ||
output.beautify = options.beautify; | ||
for (var k in options.output) { | ||
// eslint-disable-line guard-for-in | ||
output[k] = options.output[k]; | ||
} | ||
var extractedComments = []; | ||
if (options.extractComments) { | ||
var condition = {}; | ||
if (typeof options.extractComments === 'string' || options.extractComments instanceof RegExp) { | ||
// extractComments specifies the extract condition and output.comments specifies the preserve condition | ||
condition.preserve = output.comments; | ||
condition.extract = options.extractComments; | ||
} else if (Object.prototype.hasOwnProperty.call(options.extractComments, 'condition')) { | ||
// Extract condition is given in extractComments.condition | ||
condition.preserve = output.comments; | ||
condition.extract = options.extractComments.condition; | ||
} else { | ||
// No extract condition is given. Extract comments that match output.comments instead of preserving them | ||
condition.preserve = false; | ||
condition.extract = output.comments; | ||
} | ||
// Write extracted comments to commentsFile | ||
var commentsSource = new RawSource(extractedComments.join("\n\n") + "\n"); | ||
if (commentsFile in compilation.assets) { | ||
// commentsFile already exists, append new comments... | ||
if (compilation.assets[commentsFile] instanceof ConcatSource) { | ||
compilation.assets[commentsFile].add("\n"); | ||
compilation.assets[commentsFile].add(commentsSource); | ||
} else { | ||
compilation.assets[commentsFile] = new ConcatSource(compilation.assets[commentsFile], "\n", commentsSource); | ||
} | ||
} else { | ||
compilation.assets[commentsFile] = commentsSource; | ||
} | ||
// Ensure that both conditions are functions | ||
['preserve', 'extract'].forEach(function (key) { | ||
switch (typeof condition[key]) { | ||
case 'boolean': | ||
{ | ||
var b = condition[key]; | ||
condition[key] = function () { | ||
return b; | ||
}; | ||
break; | ||
} | ||
case 'function': | ||
break; | ||
case 'string': | ||
{ | ||
if (condition[key] === 'all') { | ||
condition[key] = function () { | ||
return true; | ||
}; | ||
break; | ||
} | ||
var regex = new RegExp(condition[key]); | ||
condition[key] = function (astNode, comment) { | ||
return regex.test(comment.value); | ||
}; | ||
break; | ||
} | ||
default: | ||
{ | ||
var defaultRegex = condition[key]; | ||
condition[key] = function (astNode, comment) { | ||
return defaultRegex.test(comment.value); | ||
}; | ||
} | ||
} | ||
}); | ||
// Add a banner to the original file | ||
if (options.extractComments.banner !== false) { | ||
var banner = options.extractComments.banner || "For license information please see " + commentsFile; | ||
if (typeof banner === "function") { | ||
banner = banner(commentsFile); | ||
} | ||
if (banner) { | ||
outputSource = new ConcatSource("/*! " + banner + " */\n", outputSource); | ||
} | ||
} | ||
} | ||
asset.__UglifyJsPlugin = compilation.assets[file] = outputSource; | ||
if (warnings.length > 0) { | ||
compilation.warnings.push(new Error(file + " from UglifyJs\n" + warnings.join("\n"))); | ||
} | ||
} catch (err) { | ||
if (err.line) { | ||
var original = sourceMap && sourceMap.originalPositionFor({ | ||
line: err.line, | ||
column: err.col | ||
}); | ||
if (original && original.source) { | ||
compilation.errors.push(new Error(file + " from UglifyJs\n" + err.message + " [" + requestShortener.shorten(original.source) + ":" + original.line + "," + original.column + "][" + file + ":" + err.line + "," + err.col + "]")); | ||
} else { | ||
compilation.errors.push(new Error(file + " from UglifyJs\n" + err.message + " [" + file + ":" + err.line + "," + err.col + "]")); | ||
} | ||
} else if (err.msg) { | ||
compilation.errors.push(new Error(file + " from UglifyJs\n" + err.msg)); | ||
} else compilation.errors.push(new Error(file + " from UglifyJs\n" + err.stack)); | ||
} finally { | ||
uglify.AST_Node.warn_function = oldWarnFunction; // eslint-disable-line camelcase | ||
} | ||
}); | ||
callback(); | ||
}); | ||
}); | ||
} | ||
}]); | ||
// Redefine the comments function to extract and preserve | ||
// comments according to the two conditions | ||
output.comments = function (astNode, comment) { | ||
if (condition.extract(astNode, comment)) { | ||
extractedComments.push(comment.type === 'comment2' ? `/*${comment.value}*/` : `//${comment.value}`); | ||
} | ||
return condition.preserve(astNode, comment); | ||
}; | ||
} | ||
var map = void 0; | ||
if (options.sourceMap) { | ||
map = _uglifyJs2.default.SourceMap({ // eslint-disable-line new-cap | ||
file, | ||
root: '' | ||
}); | ||
output.source_map = map; // eslint-disable-line camelcase | ||
} | ||
var stream = _uglifyJs2.default.OutputStream(output); // eslint-disable-line new-cap | ||
ast.print(stream); | ||
if (map) map += ''; | ||
var stringifiedStream = `${stream}`; | ||
var outputSource = map ? new _webpackSources.SourceMapSource(stringifiedStream, file, JSON.parse(map), input, inputSourceMap // eslint-disable-line comma-dangle | ||
) : new _webpackSources.RawSource(stringifiedStream); | ||
if (extractedComments.length > 0) { | ||
var commentsFile = options.extractComments.filename || `${file}.LICENSE`; | ||
if (typeof commentsFile === 'function') { | ||
commentsFile = commentsFile(file); | ||
} | ||
return UglifyJsPlugin; | ||
// Write extracted comments to commentsFile | ||
var commentsSource = new _webpackSources.RawSource(`${extractedComments.join('\n\n')}\n`); | ||
if (commentsFile in compilation.assets) { | ||
// commentsFile already exists, append new comments... | ||
if (compilation.assets[commentsFile] instanceof _webpackSources.ConcatSource) { | ||
compilation.assets[commentsFile].add('\n'); | ||
compilation.assets[commentsFile].add(commentsSource); | ||
} else { | ||
compilation.assets[commentsFile] = new _webpackSources.ConcatSource(compilation.assets[commentsFile], '\n', commentsSource); | ||
} | ||
} else { | ||
compilation.assets[commentsFile] = commentsSource; | ||
} | ||
// Add a banner to the original file | ||
if (options.extractComments.banner !== false) { | ||
var banner = options.extractComments.banner || `For license information please see ${commentsFile}`; | ||
if (typeof banner === 'function') { | ||
banner = banner(commentsFile); | ||
} | ||
if (banner) { | ||
outputSource = new _webpackSources.ConcatSource(`/*! ${banner} */\n`, outputSource); | ||
} | ||
} | ||
} | ||
uglifiedAssets.add(compilation.assets[file] = outputSource); | ||
if (warnings.length > 0) { | ||
compilation.warnings.push(new Error(`${file} from UglifyJs\n${warnings.join('\n')}`)); | ||
} | ||
} catch (err) { | ||
if (err.line) { | ||
var original = sourceMap && sourceMap.originalPositionFor({ | ||
line: err.line, | ||
column: err.col | ||
}); | ||
if (original && original.source) { | ||
compilation.errors.push(new Error(`${file} from UglifyJs\n${err.message} [${requestShortener.shorten(original.source)}:${original.line},${original.column}][${file}:${err.line},${err.col}]`)); | ||
} else { | ||
compilation.errors.push(new Error(`${file} from UglifyJs\n${err.message} [${file}:${err.line},${err.col}]`)); | ||
} | ||
} else if (err.msg) { | ||
compilation.errors.push(new Error(`${file} from UglifyJs\n${err.msg}`)); | ||
} else { | ||
compilation.errors.push(new Error(`${file} from UglifyJs\n${err.stack}`)); | ||
} | ||
} finally { | ||
_uglifyJs2.default.AST_Node.warn_function = oldWarnFunction; // eslint-disable-line camelcase | ||
} | ||
}); | ||
callback(); | ||
}); | ||
}); | ||
} | ||
}]); | ||
return UglifyJsPlugin; | ||
}(); | ||
module.exports = UglifyJsPlugin; | ||
exports.default = UglifyJsPlugin; |
111
package.json
{ | ||
"name": "uglifyjs-webpack-plugin", | ||
"version": "0.4.6", | ||
"version": "1.0.0-beta.0", | ||
"description": "UglifyJS plugin for webpack", | ||
"main": "./dist", | ||
"author": "webpack Contrib Team", | ||
"license": "MIT", | ||
"main": "dist/cjs.js", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "babel src -d dist", | ||
"start": "npm run build -- -w", | ||
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js'", | ||
"test:all": "npm run test:coverage && npm run test:lint", | ||
"test": "jest --", | ||
"test:coverage": "jest --coverage --", | ||
"test:watch": "jest --watch --", | ||
"test": "jest", | ||
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage", | ||
"test:watch": "jest --watch", | ||
"test:lint": "eslint . --ext .js --ignore-path .gitignore --cache", | ||
"preversion": "npm run test:all && npm run build && git commit --allow-empty -am \"Update dist\"", | ||
"postinstall": "node lib/post_install.js" | ||
"prebuild": "npm run clean", | ||
"clean": "del-cli dist", | ||
"lint": "eslint --cache src test", | ||
"lint-staged": "lint-staged", | ||
"prepublish": "npm run build", | ||
"release": "standard-version", | ||
"security": "nsp check", | ||
"travis:lint": "npm run lint && npm run security", | ||
"travis:test": "npm run test -- --runInBand", | ||
"travis:coverage": "npm run test:coverage -- --runInBand", | ||
"appveyor:test": "npm run test", | ||
"webpack-defaults": "webpack-defaults" | ||
}, | ||
"dependencies": { | ||
"source-map": "^0.5.6", | ||
"uglify-js": "^2.8.29", | ||
"webpack-sources": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"babel-jest": "^20.0.3", | ||
"babel-plugin-transform-object-rest-spread": "^6.23.0", | ||
"babel-polyfill": "^6.23.0", | ||
"babel-preset-env": "^1.5.2", | ||
"cross-env": "^5.0.1", | ||
"del-cli": "^1.0.0", | ||
"eslint": "^4.0.0", | ||
"eslint-config-webpack": "^1.2.3", | ||
"eslint-plugin-import": "^2.3.0", | ||
"jest": "^20.0.4", | ||
"lint-staged": "^4.0.0", | ||
"memory-fs": "^0.4.1", | ||
"nsp": "^2.6.3", | ||
"pre-commit": "^1.2.2", | ||
"standard-version": "^4.1.0", | ||
"uglify-js": "^2.8.18", | ||
"webpack": "^3.0.0", | ||
"webpack-defaults": "^1.4.0" | ||
}, | ||
"repository": { | ||
@@ -25,17 +67,2 @@ "type": "git", | ||
], | ||
"files": [ | ||
"dist", | ||
"lib" | ||
], | ||
"jest": { | ||
"collectCoverage": true, | ||
"moduleFileExtensions": [ | ||
"js" | ||
], | ||
"moduleDirectories": [ | ||
"node_modules" | ||
] | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"bugs": { | ||
@@ -46,34 +73,14 @@ "url": "https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues" | ||
"peerDependencies": { | ||
"webpack": "^1.9 || ^2 || ^2.1.0-beta || ^2.2.0-rc || ^3.0.0" | ||
"webpack": "^2.0.0 || ^3.0.0" | ||
}, | ||
"dependencies": { | ||
"source-map": "^0.5.6", | ||
"uglify-js": "^2.8.29", | ||
"webpack-sources": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.18.0", | ||
"babel-core": "^6.21.0", | ||
"babel-eslint": "^7.1.1", | ||
"babel-jest": "^18.0.0", | ||
"babel-plugin-syntax-object-rest-spread": "^6.13.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.20.2", | ||
"babel-preset-es2015": "^6.18.0", | ||
"eslint": "^3.13.1", | ||
"eslint-config-airbnb": "^14.0.0", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-jsx-a11y": "^3.0.2", | ||
"eslint-plugin-node": "^4.0.1", | ||
"eslint-plugin-react": "^6.9.0", | ||
"git-prepush-hook": "^1.0.1", | ||
"jest": "^18.1.0", | ||
"sync-exec": "^0.6.2", | ||
"webpack": "^2.2.0" | ||
}, | ||
"engines": { | ||
"node": ">=4.3.0 <5.0.0 || >=5.10" | ||
"node": ">= 4.3 < 5.0.0 || >= 5.10" | ||
}, | ||
"pre-push": [ | ||
"test:all" | ||
] | ||
"pre-commit": "lint-staged", | ||
"lint-staged": { | ||
"*.js": [ | ||
"eslint --fix", | ||
"git add" | ||
] | ||
} | ||
} |
@@ -74,3 +74,3 @@ [![npm][npm]][npm-url] | ||
| comments | boolean, RegExp, function(astNode, comment) -> boolean | Defaults to preserving comments containing `/*!`, `/**!`, `@preserve` or `@license`. | Comment related configuration. | | ||
| extractComments | boolean, RegExp, function (astNode, comment) -> boolean, object | false | Whether comments shall be extracted to a separate file, see below. | | ||
| extractComments | boolean, RegExp, function (astNode, comment) -> boolean, object | false | Whether comments shall be extracted to a separate file, (see [details](https://github.com/webpack/webpack/commit/71933e979e51c533b432658d5e37917f9e71595a), since webpack 2.3.0) | | ||
| sourceMap | boolean | false | Use SourceMaps to map error message locations to modules. This slows down the compilation. **Important!** `cheap` source map options don't work with the plugin! | | ||
@@ -80,3 +80,2 @@ | test | RegExp, Array<RegExp> | <code>/\.js($|\?)/i</code> | Test to match files against. | | ||
| exclude | RegExp, Array<RegExp> | | Files to `exclude` from testing. | | ||
| extractComments | boolean, RegExp, object | | Extract comments to separate file (see [details](https://github.com/webpack/webpack/commit/71933e979e51c533b432658d5e37917f9e71595a), since webpack 2.3.0) | | ||
| warningsFilter | function(source) -> boolean | | Allow to filter uglify warnings (since webpack 2.3.0) | | ||
@@ -83,0 +82,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
28455
1
0
0
19
172
2