Coder Social home page Coder Social logo

vikibeta / uglifyjs-webpack-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aui/uglifyjs-webpack-plugin

0.0 2.0 0.0 267 KB

UglifyJS plugin for webpack

Home Page: https://www.npmjs.com/package/uglifyjs-webpack-plugin

License: MIT License

JavaScript 100.00%

uglifyjs-webpack-plugin's Introduction

npm deps test coverage quality chat

UglifyJS Webpack Plugin

This plugin uses UglifyJS v2 to minify your JavaScript.

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.

Install

With Yarn:

yarn add uglifyjs-webpack-plugin --dev

With npm:

npm install uglifyjs-webpack-plugin --save-dev

Important! The plugin has a peer dependency to uglify-js, so in order to use the plugin, also uglify-js has to be installed. The currently (2017/1/25) available uglify-js npm packages; however, do not support minification of ES6 code. In order to support ES6, an ES6-capable, a.k.a. harmony, version of UglifyJS has to be provided.

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

Usage

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

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

Options

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 details, 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!
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.
warningsFilter function(source) -> boolean Allow to filter uglify warnings (since webpack 2.3.0)
parallel boolean, object false Use multi-process parallel running and file cache to improve the build speed.

Mangling

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
  }
})

Extracting Comments

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 */

Run in parallel

The parallel option can be

  • true: Enable multi-process parallel running with file cache
  • an object consisting of the following keys, all optional:
    • workers: The maximum number of concurrent runs. If it is true, it is equal to require('os').cpus().length - 1.
    • cache: Enable file caching. If it is true, it is equal to "node_modules/.cache/uglifyjs-webpack-plugin".

Maintainers


Juho Vepsäläinen

Joshua Wiens

Kees Kluskens

Sean Larkin

uglifyjs-webpack-plugin's People

Contributors

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

Watchers

James Cloos avatar KingxBeta 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.