Socket
Socket
Sign inDemoInstall

uglifyjs-webpack-plugin

Package Overview
Dependencies
Maintainers
4
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uglifyjs-webpack-plugin - npm Package Compare versions

Comparing version 1.0.0-beta.2 to 1.0.0-beta.3

5

CHANGELOG.md

@@ -5,2 +5,7 @@ # Change Log

<a name="1.0.0-beta.3"></a>
# [1.0.0-beta.3](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/compare/v1.0.0-beta.2...v1.0.0-beta.3) (2017-09-29)
<a name="1.0.0-beta.2"></a>

@@ -7,0 +12,0 @@ # [1.0.0-beta.2](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/compare/v1.0.0-beta.1...v1.0.0-beta.2) (2017-07-21)

42

dist/index.js

@@ -36,2 +36,8 @@ 'use strict';

var _serialization = require('./uglify/serialization');
var _versions = require('./uglify/versions');
var _versions2 = _interopRequireDefault(_versions);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -63,5 +69,10 @@

} : _options$warningsFilt,
extractComments = options.extractComments,
sourceMap = options.sourceMap,
parallel = options.parallel;
_options$extractComme = options.extractComments,
extractComments = _options$extractComme === undefined ? false : _options$extractComme,
_options$sourceMap = options.sourceMap,
sourceMap = _options$sourceMap === undefined ? false : _options$sourceMap,
_options$cache = options.cache,
cache = _options$cache === undefined ? false : _options$cache,
_options$parallel = options.parallel,
parallel = _options$parallel === undefined ? false : _options$parallel;

@@ -74,2 +85,3 @@

sourceMap,
cache,
parallel,

@@ -100,3 +112,6 @@ uglifyOptions: Object.assign({

compilation.plugin('optimize-chunk-assets', function (chunks, callback) {
var uglify = new _uglify2.default(_this.options.parallel);
var uglify = new _uglify2.default({
cache: _this.options.cache,
parallel: _this.options.parallel
});
var uglifiedAssets = new WeakSet();

@@ -116,3 +131,3 @@ var tasks = [];

var inputSourceMap = void 0;
var cacheKey = `${compiler.outputPath}/${file}`;
if (_this.options.sourceMap) {

@@ -141,4 +156,3 @@ if (asset.sourceAndMap) {

tasks.push({
cacheKey,
var task = {
file,

@@ -151,3 +165,15 @@ input,

uglifyOptions: _this.options.uglifyOptions
});
};
if (_this.options.cache) {
task.cacheKey = JSON.stringify({
'uglify-es': _versions2.default.uglify,
'uglifyjs-webpack-plugin': _versions2.default.plugin,
'uglifyjs-webpack-plugin-options': _this.options,
path: compiler.outputPath ? `${compiler.outputPath}/${file}` : file,
input
}, _serialization.encode);
}
tasks.push(task);
} catch (error) {

@@ -154,0 +180,0 @@ compilation.errors.push(UglifyJsPlugin.buildError(error, file, sourceMap, compilation, requestShortener));

24

dist/options.json

@@ -7,22 +7,12 @@ {

"exclude": {},
"cache": {
"oneOf": [
{ "type": "boolean" },
{ "type": "string" }
]
},
"parallel": {
"oneOf": [
{ "type": "boolean" },
{
"type": "object",
"properties": {
"workers": {
"oneOf": [
{ "type": "boolean" },
{ "type": "integer" }
]
},
"cache": {
"oneOf": [
{ "type": "boolean" },
{ "type": "string" }
]
}
}
}
{ "type": "integer" }
]

@@ -29,0 +19,0 @@ },

@@ -13,2 +13,6 @@ 'use strict';

var _cacache = require('cacache');
var _cacache2 = _interopRequireDefault(_cacache);
var _findCacheDir = require('find-cache-dir');

@@ -26,10 +30,4 @@

var _cache = require('./cache');
var _serialization = require('./serialization');
var _versions = require('./versions');
var _versions2 = _interopRequireDefault(_versions);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -48,35 +46,34 @@

function _class() {
var parallel = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, _class);
var options = parallel;
if (typeof parallel === 'boolean') {
options = { cache: parallel, workers: parallel };
}
var _options = options,
cache = _options.cache,
workers = _options.workers;
var cache = options.cache,
parallel = options.parallel;
this.cache = cache === true ? (0, _findCacheDir2.default)({ name: 'uglifyjs-webpack-plugin' }) : cache;
this.workers = workers === true ? _os2.default.cpus().length - 1 : Math.min(Number(workers) || 0, _os2.default.cpus().length - 1);
this.cacheDir = cache === true ? (0, _findCacheDir2.default)({ name: 'uglifyjs-webpack-plugin' }) : cache;
this.maxConcurrentWorkers = parallel === true ? _os2.default.cpus().length - 1 : Math.min(Number(parallel) || 0, _os2.default.cpus().length - 1);
}
_createClass(_class, [{
key: 'worker',
value: function worker(options, callback) {
key: 'runTasks',
value: function runTasks(tasks, callback) {
var _this = this;
if (this.workers > 0) {
this.workerFarm = (0, _workerFarm2.default)({
maxConcurrentWorkers: this.workers
if (!tasks.length) {
callback(null, []);
return;
}
if (this.maxConcurrentWorkers > 0) {
this.workers = (0, _workerFarm2.default)({
maxConcurrentWorkers: this.maxConcurrentWorkers
}, workerFile);
this.worker = function (opt, cb) {
return _this.workerFarm(JSON.stringify(opt, _serialization.encode), cb);
this.boundWorkers = function (options, cb) {
return _this.workers(JSON.stringify(options, _serialization.encode), cb);
};
} else {
this.worker = function (opt, cb) {
this.boundWorkers = function (options, cb) {
try {
var result = (0, _minify2.default)(opt);
cb(null, result);
cb(null, (0, _minify2.default)(options));
} catch (errors) {

@@ -88,21 +85,2 @@ cb(errors);

this.worker(options, callback);
}
}, {
key: 'exit',
value: function exit() {
if (this.workerFarm) {
_workerFarm2.default.end(this.workerFarm);
}
}
}, {
key: 'runTasks',
value: function runTasks(tasks, callback) {
var _this2 = this;
if (!tasks.length) {
callback(null, []);
return;
}
var toRun = tasks.length;

@@ -113,2 +91,3 @@ var results = [];

results[index] = data;
if (!toRun) {

@@ -120,5 +99,4 @@ callback(null, results);

tasks.forEach(function (task, index) {
var cacheIdentifier = `${_versions2.default.uglify}|${_versions2.default.plugin}|${task.input}`;
var enqueue = function enqueue() {
_this2.worker(task, function (error, data) {
_this.boundWorkers(task, function (error, data) {
var result = error ? { error } : data;

@@ -128,4 +106,5 @@ var done = function done() {

};
if (_this2.cache && !result.error) {
(0, _cache.put)(_this2.cache, task.cacheKey, data, cacheIdentifier).then(done, done);
if (_this.cacheDir && !result.error) {
_cacache2.default.put(_this.cacheDir, task.cacheKey, JSON.stringify(data)).then(done, done);
} else {

@@ -136,5 +115,7 @@ done();

};
if (_this2.cache) {
(0, _cache.get)(_this2.cache, task.cacheKey, cacheIdentifier).then(function (data) {
return step(index, data);
if (_this.cacheDir) {
_cacache2.default.get(_this.cacheDir, task.cacheKey).then(function (_ref) {
var data = _ref.data;
return step(index, JSON.parse(data));
}, enqueue);

@@ -146,2 +127,9 @@ } else {

}
}, {
key: 'exit',
value: function exit() {
if (this.workers) {
_workerFarm2.default.end(this.workers);
}
}
}]);

@@ -148,0 +136,0 @@

{
"name": "uglifyjs-webpack-plugin",
"version": "1.0.0-beta.2",
"version": "1.0.0-beta.3",
"description": "UglifyJS plugin for webpack",

@@ -5,0 +5,0 @@ "author": "webpack Contrib Team",

@@ -15,3 +15,3 @@ [![npm][npm]][npm-url]

<h1>UglifyJS Webpack Plugin</h1>
<p>This plugin uses <a href="https://github.com/mishoo/UglifyJS2/tree/harmony">UglifyJS v3</a> to minify your JavaScript<p>
<p>This plugin uses <a href="https://github.com/mishoo/UglifyJS2/tree/harmony">UglifyJS v3 </a><a href="https://npmjs.com/package/uglify-es">(`uglify-es`)</a> to minify your JavaScript<p>
</div>

@@ -42,2 +42,4 @@

> ⚠️ The following options are for the latest beta version. If you would like to see the options for the latest built-in version of the plugin in webpack, see the [v0.4.6 docs](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/tree/v0.4.6).
|Name|Type|Default|Description|

@@ -48,7 +50,8 @@ |:--:|:--:|:-----:|:----------|

|**`exclude`**|`{RegExp\|Array<RegExp>}`|`undefined`|Files to `exclude`|
|**`parallel`**|`{Boolean\|Object}`|`false`|Use multi-process parallel running and file cache to improve the build speed|
|**`cache`**|`{Boolean\|String}`|`false`|Enable file caching|
|**`parallel`**|`{Boolean\|Number}`|`false`|Use multi-process parallel running and file cache to improve the build speed|
|**`sourceMap`**|`{Boolean}`|`false`|Use source maps to map error message locations to modules (This slows down the compilation) ⚠️ **`cheap-source-map` options don't work with this plugin**|
|**`uglifyOptions`**|`{Object}`|[`{...defaults}`](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/tree/master#uglifyoptions)|`uglify` [Options](https://github.com/mishoo/UglifyJS2/tree/harmony#minify-options)|
|**`extractComments`**|`{Boolean\|RegExp\|Function<(node, comment) -> {Boolean\|Object}>}`|`false`|Whether comments shall be extracted to a separate file, (see [details](https://github.com/webpack/webpack/commit/71933e979e51c533b432658d5e37917f9e71595a) (`webpack >= 2.3.0`)|
|**`warningsFilter`**|`{Function(source) -> {Boolean}}`|``|Allow to filter uglify warnings|
|**`warningsFilter`**|`{Function(source) -> {Boolean}}`|`() => true`|Allow to filter uglify warnings|

@@ -88,4 +91,35 @@ ### `test`

### `cache`
**`{Boolean}`**
**webpack.config.js**
```js
[
new UglifyJSPlugin({
cache: true
})
]
```
Enable file caching.
Default path to cache directory: `node_modules/.cache/uglifyjs-webpack-plugin`.
**`{String}`**
**webpack.config.js**
```js
[
new UglifyJSPlugin({
cache: 'path/to/cache'
})
]
```
Path to cache directory.
### `parallel`
**`{Boolean}`**
**webpack.config.js**

@@ -100,7 +134,7 @@ ```js

|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|**`cache`**|`{Boolean}`|`node_modules/.cache/uglifyjs-webpack-plugin`|Enable file caching|
|**`workers`**|`{Boolean\|Object}`|`os.cpus().length - 1`|Number of concurrent runs, default is the `maximum`|
Enable parallelization.
Default number of concurrent runs: `os.cpus().length - 1`.
**`{Number}`**
**webpack.config.js**

@@ -110,6 +144,3 @@ ```js

new UglifyJSPlugin({
parallel: {
cache: true
workers: 2 // for e.g
}
parallel: 4
})

@@ -119,2 +150,4 @@ ]

Number of concurrent runs.
> ℹ️ Parallelization can speedup your build significantly and is therefore **highly recommended**

@@ -177,3 +210,3 @@

All comments that normally would be preserved by the `comments` option will be moved to a separate file. If the original file is named `foo.js`, then the comments will be stored to `foo.js.LICENSE`
All comments that normally would be preserved by the `comments` option will be moved to a separate file. If the original file is named `foo.js`, then the comments will be stored to `foo.js.LICENSE`.

@@ -180,0 +213,0 @@ **`{RegExp|String}` or `{Function<(node, comment) -> {Boolean}>}`**

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