Giter Club home page Giter Club logo

uglifyjs-webpack-plugin's Introduction

npm node deps test coverage chat

UglifyJS Webpack Plugin

This plugin uses UglifyJS v3 (`uglify-es`) to minify your JavaScript

ℹ️ webpack contains the same plugin under webpack.optimize.UglifyJsPlugin. The documentation is valid apart from the installation instructions

Install

npm i -D uglifyjs-webpack-plugin

Usage

webpack.config.js

const UglifyJSPlugin = require('uglifyjs-webpack-plugin')

module.exports = {
  plugins: [
    new UglifyJSPlugin()
  ]
}

Options

⚠️ 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.

Name Type Default Description
test {RegExp|Array<RegExp>} /\.js$/i Test to match files against
include {RegExp|Array<RegExp>} undefined Files to include
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
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} uglify Options
extractComments {Boolean|RegExp|Function<(node, comment) -> {Boolean|Object}>} false Whether comments shall be extracted to a separate file, (see details (webpack >= 2.3.0)
warningsFilter {Function(source) -> {Boolean}} undefined Allow to filter uglify warnings

test

webpack.config.js

[
  new UglifyJSPlugin({
    test: /\.js($&#124;\?)/i
  })
]

include

webpack.config.js

[
  new UglifyJSPlugin({
    include: /\/includes/
  })
]

exclude

webpack.config.js

[
  new UglifyJSPlugin({
    exclude: /\/excludes/
  })
]

parallel

webpack.config.js

[
  new UglifyJSPlugin({
    parallel: true
  })
]
Name Type Default Description
cache {Boolean} node_modules/.cache/uglifyjs-webpack-plugin Enable file caching
workers {Boolean|Number} os.cpus().length - 1 Number of concurrent runs, default is the maximum

webpack.config.js

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

ℹ️ Parallelization can speedup your build significantly and is therefore highly recommended

sourceMap

webpack.config.js

[
  new UglifyJSPlugin({
    sourceMap: true
  })
]

⚠️ cheap-source-map options don't work with this plugin

Name Type Default Description
ie8 {Boolean} false Enable IE8 Support
ecma {Number} undefined Supported ECMAScript Version (5, 6, 7 or 8). Affects parse, compress && output options
parse {Object} {} Additional Parse Options
mangle {Boolean|Object} true Enable Name Mangling (See Mangle Properties for advanced setups, use with ⚠️)
output {Object} {} Additional Output Options (The defaults are optimized for best compression)
compress {Boolean|Object} true Additional Compress Options
warnings {Boolean} false Display Warnings

webpack.config.js

[
  new UglifyJSPlugin({
    uglifyOptions: {
      ie8: false,
      ecma: 8,
      parse: {...options},
      mangle: {
        ...options,
        properties: {
          // mangle property options
        }
      },
      output: {
        comments: false,
        beautify: false,
        ...options
      },
      compress: {...options},
      warnings: false
    }
  })
]

extractComments

{Boolean}

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

{RegExp|String} or {Function<(node, 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.

{Object}

Name Type Default Description
condition {Regex|Function} `` Regular Expression or function (see previous point)
filename {String|Function} compilation.assets[file] The file where the extracted comments will be stored. Can be either a {String} or a {Function<(string) -> {String}>}, which will be given the original filename. Default is to append the suffix .LICENSE to the original filename
banner {Boolean|String|Function} /*! For license information please see ${filename}.js.LICENSE */ The banner text that points to the extracted file and will be added on top of 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

warningsFilter

webpack.config.js

[
  new UglifyJsPlugin({
    warningsFilter: (src) => true
  })
]

Maintainers


Steven Hargrove

Juho Vepsäläinen

Joshua Wiens

Michael Ciniawsky

Alexander Krasnoyarov

uglifyjs-webpack-plugin's People

Contributors

bebraw avatar joshwiens avatar thelarkinn avatar sebastians90 avatar hulkish avatar michael-ciniawsky avatar arunoda avatar mkarajohn avatar dru89 avatar evilebottnawi avatar hartorn avatar jemarjones avatar lencioni avatar jharris4 avatar julkue avatar jumoel avatar mlazowik avatar patrickjs avatar pierreneter avatar piperchester avatar simon04 avatar vadimbrodsky avatar lucapette avatar aui avatar

Watchers

Francesc Rosas avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.