npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sandfox/uglifyjs-webpack-plugin

v0.4.8

Published

UglifyJS plugin for webpack

Downloads

2

Readme

npm deps test coverage quality chat

Note that webpack contains the same plugin under webpack.optimize.UglifyJsPlugin. This is a standalone version for those that want to control the version of UglifyJS. The documentation is valid apart from the installation instructions in that case.

With Yarn:

yarn add @sandfox/uglifyjs-webpack-plugin --dev

With npm:

npm install @sandfox/uglifyjs-webpack-plugin --save-dev

Important! The plugin has the harmony branch hard-coded!

If your minification target is ES6:

yarn add git://github.com/mishoo/UglifyJS2#harmony-v2.8.22 --dev

If your minification target is ES5:

yarn add uglify-js --dev
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
  entry: {...},
  output: {...},
  module: {...},
  plugins: [
    new UglifyJSPlugin()
  ]
};

This plugin supports UglifyJS features as discussed below:

| Property | Type | Default | Description | | --- | --- | --- | --- | | compress | boolean, object | true | See UglifyJS documentation. | | mangle | boolean, object | true | See below. | | beautify | boolean | false | Beautify output. | | output | An object providing options for UglifyJS OutputStream | | Lower level access to UglifyJS output. | | 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. | | 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! | | test | RegExp, Array | /.js($|?)/i | Test to match files against. | | include | RegExp, Array | | Test only include files. | | exclude | RegExp, Array | | Files to exclude from testing. | | extractComments | boolean, RegExp, object | | Extract comments to separate file (see details, since webpack 2.3.0) | | warningsFilter | function(source) -> boolean | | Allow to filter uglify warnings (since webpack 2.3.0) |

mangle (boolean|object) - Passing true or an object enables and provides options for UglifyJS name mangling. See UglifyJS documentation for mangle options. Example configuration, this will not mangle properties (see below):

new UglifyJsPlugin({
  mangle: {
    // Skip mangling these
    except: ['$super', '$', 'exports', 'require']
  }
})

mangle.props (boolean|object) - Passing true or an object enables and provides options for UglifyJS property mangling - see UglifyJS documentation for mangleProperties options.

Note: the UglifyJS docs warn that you will probably break your source if you use property mangling, so if you aren’t sure why you’d need this feature, you most likely shouldn’t be using it! This is not enabled by default.

Example configuration, this will mangle both names and properties:

new UglifyJsPlugin({
  mangle: {
    props: true
  }
})

The extractComments option can be

  • true: 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
  • regular expression (given as RegExp or string) or a function (astNode, comment) -> boolean: All comments that match the given expression (resp. are evaluated to true by the function) will be extracted to the separate file. The comments option specifies whether the comment will be preserved, i.e. it is possible to preserve some comments (e.g. annotations) while extracting others or even preserving comments that have been extracted.
  • an object consisting of the following keys, all optional:
    • condition: regular expression or function (see previous point)
    • filename: The file where the extracted comments will be stored. Can be either a string or function (string) -> string which will be given the original filename. Default is to append the suffix .LICENSE to the original filename.
    • banner: The banner text that points to the extracted file and will be added on top of the original file. will be added to the original file. Can be false (no banner), a string, or a function (string) -> string that will be called with the filename where extracted comments have been stored. Will be wrapped into comment. Default: /*! For license information please see foo.js.LICENSE */