Giter VIP home page Giter VIP logo

rollup-plugin-uglify's Introduction

rollup-plugin-uglify Travis Build Status

Rollup plugin to minify generated bundle. Uses UglifyJS under the hood. There are a few improvements over native uglify:

  • uglify is run in worker for every chunk
  • errors are displayed with babel code frame

Note: uglify-js is able to transpile only es5 syntax. If you want to transpile es6+ syntax use terser instead

Install

yarn add rollup-plugin-uglify --dev

Note: this package requires [email protected] and higher

Usage

import { rollup } from "rollup";
import { uglify } from "rollup-plugin-uglify";

rollup({
  input: "main.js",
  plugins: [uglify()]
});

Options

uglify(options);

options - uglifyJS API options

options.sourcemap: boolean

Generates source maps and passes them to rollup. Defaults to true.

options.numWorkers: number

Amount of workers to spawn. Defaults to the number of CPUs minus 1.

Examples

Comments

If you'd like to preserve comments (for licensing for example), then you can specify a function to do this like so:

uglify({
  output: {
    comments: function(node, comment) {
      if (comment.type === "comment2") {
        // multiline comment
        return /@preserve|@license|@cc_on/i.test(comment.value);
      }
      return false;
    }
  }
});

Alternatively, you can also choose to keep all comments (e.g. if a licensing header has already been prepended by a previous rollup plugin):

uglify({
  output: {
    comments: "all"
  }
});

See UglifyJS documentation for further reference.

License

MIT © Bogdan Chadkin

rollup-plugin-uglify's People

Contributors

andarist avatar anmonteiro avatar bfred-it avatar davidkna avatar dbrgn avatar grawl avatar jltrv avatar kzc avatar lc-soft avatar patrickarlt avatar ratson avatar trysound avatar uorbe001 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rollup-plugin-uglify's Issues

Using the plugin for third party libraries

Hi,
I'm using the plugin in combination with rollup-plugin-typescript2.
In my code I'm referencing lodash.clonedeep as external dependency (so it is not included in the bundle).
I get the following error:
(uglify plugin) Error: Error transforming bundle with 'uglify' plugin: Unexpected token: name (cloneDeep)
Error: Error transforming bundle with 'uglify' plugin: Unexpected token: name (cloneDeep)"

My plugins section in rollup.config.js is:


   plugins: [
      // rollup-plugin-typescript2 config.
        typescript({
            tsconfig: "tsconfig.json",
            verbosity: 3,  // 0 -- Error, 1 -- Warning, 2 -- Info, 3 -- Debug
            cacheRoot: "./.rollup-plugin-typescript2_cache",
            clean: true // Set to true for clean build (wipes out cache on every build).
        }),
        uglify()
    ]
 

By the way I tried 'rollup-plugin-uglify-es' and does not throw this error.

my tsconfig.json:


{
  "compileOnSave": true,
  "compilerOptions": {
    "outDir": "./build/compiled",
    "module": "ES2015",
    "target": "es5",
    "moduleResolution": "node",
    "lib": ["ES2016", "ES2017"],
    "sourceMap": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "downlevelIteration": true,
    "declaration": true,
    "alwaysStrict": true,
    "strict": true,
    "allowJs": false
  },
  "include": [
    "./src/**/*",
    "./spec/**/*",
    "./test/**/*"
  ],
  "exclude": [
    "node_modules"
  ]
}

Fails with (uglify plugin) TypeError: regex.test is not a function

When passing an Uglify option that is a regex, Uglify fails with error TypeError: regex.test is not a function as it seems rollup-plugin-uglify somehow transform regexps into strings.
It might happen when passing the option object to the jest-worker.

Here is the config to reproduce:

import { rollup } from "rollup";
import { uglify } from "rollup-plugin-uglify";

rollup({
  input: "main.js",
  plugins: [uglify({mangle: {properties: {regex: /^_/}}})]
});

Unexpected token error when using format esm

When I build my package using umd the uglify plugin works. It doesn't using esm. I already am using uglify-es:

import { minify } from 'uglify-es'
...
uglify({}, minify),

Here are the dependencies in my package.json:

    "rollup": "^1.20.3",
    "rollup-plugin-babel": "^4.3.3",
    "rollup-plugin-babel-minify": "^9.0.0",
    "rollup-plugin-commonjs": "^10.1.0",
    "rollup-plugin-copy": "^3.1.0",
    "rollup-plugin-delete": "^1.1.0",
    "rollup-plugin-json": "^4.0.0",
    "rollup-plugin-node-resolve": "^5.2.0",
    "rollup-plugin-typescript2": "^0.24.0",
    "rollup-plugin-uglify": "^6.0.3",
    "uglify-es": "^3.3.9"

my rollup.config.js:

const formats = ['umd', 'esm']

module.exports = formats.map(format => ({
  input: './src/main.ts',
  external: Object.keys(pkg.dependencies || {}),
  output: {
    name: 'test',
    file: `dist/test.${format}.js`,
    format: format,
    globals: {
      'jquery': '$'
    },
    sourcemap: true,
  },
  plugins: [
    json(),
    typescript({
      useTsconfigDeclarationDir: true,
    }),
    resolve(),
    commonjs(),
    babel({
      exclude: 'node_modules/**',
      extensions: ['.js', '.ts'],
      runtimeHelpers: true,
      sourceMap: true,
    }),
    uglify({}, minify),
  ],
}))

This is the error message I get:

./src/main.ts → dist/c4.core.esm.js...
> 1 | import $ from 'jquery';
    |       ^ Unexpected token: name «$», expected: punc «;»

[!] (plugin uglify) Error: Unexpected token: name «$», expected: punc «;»
SyntaxError: Unexpected token: name «$», expected: punc «;»
    at JS_Parse_Error.get (eval at <anonymous> (...\node_modules\uglify-js\tools\node.js:20:1), <anonymous>:71:23)
    at reportError (...\packages\test\node_modules\jest-worker\build\workers\processChild.js:107:11)
    at reportClientError (...\packages\test\node_modules\jest-worker\build\workers\processChild.js:87:10)
    at execFunction (...\packages\test\node_modules\jest-worker\build\workers\processChild.js:157:5)
    at execHelper (...\packages\test\node_modules\jest-worker\build\workers\processChild.js:139:5)
    at execMethod (...\packages\test\node_modules\jest-worker\build\workers\processChild.js:143:5)
    at process.on.request (...\packages\test\node_modules\jest-worker\build\workers\processChild.js:64:7)
    at process.emit (events.js:193:13)
    at emit (internal/child_process.js:850:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:17)

ES6 classes fail to uglify

Hi,
I'm trying to uglify one lib and it's failing to uglify, probably due to ES6 syntax. Can anyone confirm if this is an issue with ES6 class or something else? Cannot get more info, pretty new with rollup. The error is this:
[!] (uglify plugin) Error: Error transforming bundle with 'uglify' plugin: Unexpected token: name (NumberUtil)

More info can be found here: geoman-io/leaflet-geoman#255 (comment)

"preserveComments" causes error

When using uglify without the rollup plugin, it works well with the preserveComments option, but when passing that setting to the rollup-plugin-uglify I do see an error:

TypeError: Cannot set property 'comments' of null                                       
    at setup (C:\www\UI\BUILD\node_modules\gulp-uglify\minifier.js:44:29)               
    at DestroyableTransform.minify [as _transform] (C:\www\UI\BUILD\node_modules\gulp-ug
lify\minifier.js:54:19)                                                                 
    at DestroyableTransform.Transform._read (C:\www\UI\BUILD\node_modules\through2\node_
modules\readable-stream\lib\_stream_transform.js:159:10)                                
    at DestroyableTransform.Transform._write (C:\www\UI\BUILD\node_modules\through2\node
_modules\readable-stream\lib\_stream_transform.js:147:83)                               
    at doWrite (C:\www\UI\BUILD\node_modules\through2\node_modules\readable-stream\lib\_
stream_writable.js:347:64)                                                              
    at writeOrBuffer (C:\www\UI\BUILD\node_modules\through2\node_modules\readable-stream
\lib\_stream_writable.js:336:5)                                                         
    at DestroyableTransform.Writable.write (C:\www\UI\BUILD\node_modules\through2\node_m
odules\readable-stream\lib\_stream_writable.js:274:11)                                  
    at write (C:\www\UI\BUILD\node_modules\vinyl-fs\node_modules\readable-stream\lib\_st
ream_readable.js:623:24)                                                                
    at flow (C:\www\UI\BUILD\node_modules\vinyl-fs\node_modules\readable-stream\lib\_str
eam_readable.js:632:7)                                                                  
    at DestroyableTransform.pipeOnReadable (C:\www\UI\BUILD\node_modules\vinyl-fs\node_m
odules\readable-stream\lib\_stream_readable.js:664:5)                                   
    at emitNone (events.js:86:13)                                                       
    at DestroyableTransform.emit (events.js:185:7)                                      
    at emitReadable_ (C:\www\UI\BUILD\node_modules\vinyl-fs\node_modules\readable-stream
\lib\_stream_readable.js:448:10)                                                        
    at emitReadable (C:\www\UI\BUILD\node_modules\vinyl-fs\node_modules\readable-stream\
lib\_stream_readable.js:444:5)                                                          
    at readableAddChunk (C:\www\UI\BUILD\node_modules\vinyl-fs\node_modules\readable-str
eam\lib\_stream_readable.js:187:9)                                                      
    at DestroyableTransform.Readable.push (C:\www\UI\BUILD\node_modules\vinyl-fs\node_mo
dules\readable-stream\lib\_stream_readable.js:149:10)    

uglify configuration:

{
    compress: {
        drop_debugger : true,
        sequences     : true,
        conditionals  : true,
        booleans      : true,
        unused        : true,
        if_return     : true,
        join_vars     : true,
        properties    : true,
        dead_code     : true
    },
    mangle           : true,
    "screw-ie8"      : true,
    preserveComments : 'license'   //   <--------
}

Best way to pass in options to the CLI?

I was wondering what's the best way to pass in options to the CLI? I'm using rollupify and this is my current command:

$ browserify source/scripts -t [ rollupify --plugins [ rollup-plugin-uglify ]  ] -t [ babelify --presets [ es2015 ] ] -do public/bundle.js

Error: `numWorkers` is not a supported option

Full error with stack:

[!] (plugin uglify) Error: `numWorkers` is not a supported option
DefaultsError: `numWorkers` is not a supported option
    at DefaultsError.get (eval at <anonymous> (/Users/user/projects/project1/node_modules/uglify-js/tools/node.js:18:1), <anonymous>:71:23)
    at reportError (/Users/user/projects/project1/node_modules/jest-worker/build/workers/processChild.js:107:11)
    at reportClientError (/Users/user/projects/project1/node_modules/jest-worker/build/workers/processChild.js:87:10)
    at execFunction (/Users/user/projects/project1/node_modules/jest-worker/build/workers/processChild.js:157:5)
    at execHelper (/Users/user/projects/project1/node_modules/jest-worker/build/workers/processChild.js:139:5)
    at execMethod (/Users/user/projects/project1/node_modules/jest-worker/build/workers/processChild.js:143:5)
    at process.on.request (/Users/user/projects/project1/node_modules/jest-worker/build/workers/processChild.js:64:7)
    at process.emit (events.js:198:13)

Rollup config:

rollup({
  input: "main.js",
  plugins: [
    uglify({
      numWorkers: 1
    })
  ]
});

versions:

    "rollup": "^1.27.14",
    "rollup-plugin-uglify": "^6.0.4",

New release on npm?

Would it be possible to publish a new release on npm? The current release from a year ago is breaking eslint for us with the .mjs extension.

Plugin doesn't work on Virtual Machines with ubuntu when numWorkers != 1

I tried to build my code on dev machine Windows - it works fine.

Then I tried to build code on VM (VirtualBox) with Ubuntu 16.04 and 18.04 build was stop without any error. Building was stopped on step "./js/article.ts → ./www/build/article.js..."

Step by step I found a heart of bug - "numWorkers". If I set numWorkers to "1" then building work fine. otherwise, stop without error.

Useless SyntaxError Message

I've been banging my head for hours trying to track down this error, trolling through other issues in this repo (and uglify, and grunt-uglify, etc. etc.) that are similar to the point of even reporting virtually identical errors, but nothing discussed or addressed in any of those has helped. I've even gone so far as injected additional logging into rollup.js itself to get a more specific error log, but no joy.

When running rollup in production mode (uglify running with the harmony branch for es6), I get an uglify error that is absolutely useless:

Error transforming bundle with 'uglify' plugin: SyntaxError: Unexpected character '`'
Error
    at new JS_Parse_Error (eval at <anonymous> (/Users/me/Development/projectX/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1545:18)
    at js_error (eval at <anonymous> (/Users/me/Development/projectX/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1553:11)
    at parse_error (eval at <anonymous> (/Users/me/Development/projectX/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1677:9)
    at Object.next_token [as input] (eval at <anonymous> (/Users/me/Development/projectX/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1949:9)
    at next (eval at <anonymous> (/Users/me/Development/projectX/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2078:25)
    at subscripts (eval at <anonymous> (/Users/me/Development/projectX/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2774:13)
    at expr_atom (eval at <anonymous> (/Users/me/Development/projectX/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2631:20)
    at maybe_unary (eval at <anonymous> (/Users/me/Development/projectX/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2795:19)
    at expr_ops (eval at <anonymous> (/Users/me/Development/projectX/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2830:24)
    at maybe_conditional (eval at <anonymous> (/Users/me/Development/projectX/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2835:20)
    at maybe_assign (eval at <anonymous> (/Users/me/Development/projectX/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2859:20)
    at expression (eval at <anonymous> (/Users/me/Development/projectX/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2878:20)

I am using es6 templates, so there are valid backticks, I also have them in jsDocs for code formatting, so there are numerous places to check to find something...or I could actually get a useful error message that gives me a proper file.

I've also tried to find as much as I could about running rollup with some kind of debug mode, but nothing in that vein has born fruit either.

Take uglify out of the mix, no problem, its clearly related to the minification, but it just isn't helpful at tracking down the cause. I am using the rollup-plugin-uglify, but using the harmony branch from uglify-js for the minification itself, so my uglify config is thus (rollup.config.js):

import buble from 'rollup-plugin-buble';
import uglify from 'rollup-plugin-uglify';
import {minify} from 'uglify-js';
...
export default {
    ...,
    plugins: [
        uglify({}, minify)
    ]
}

At this point it may just be faster to just start excluding parts of my bundle until I hit on it, but I also want to be able to debug this more easily in the future as that is always the ideal.

What am I missing?

  • npm 3.10.8
  • node 5.6.0
  • Rollup 0.36.0
  • rollup-plugin-buble 0.14.0
  • uglify-js (for minify) 2.7.3
  • rollup-plugin-uglify 1.0.1

Thanks.

how to set option for double rollup.output

for example
output: [{
file: 'index.js'
},{
file: 'index.es.js'
}]
how can i set options of uglify, to make tow output files.
one file use uglify, and another don't use

and ps, when i using uglify, sometimes, running 'rollup -c', it will no response

TypeError: rollupPluginUglify.uglify is not a function

While building, I get the following error:

[!] TypeError: rollupPluginUglify.uglify is not a function
TypeError: rollupPluginUglify.uglify is not a function
    at Object.<anonymous> (/root/timeago/node-timeago.js/rollup.config.js:25:26)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.require.extensions..js (/usr/share/nodejs/rollup/bin/src/run/loadConfigFile.js:39:24)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at /usr/share/nodejs/rollup/bin/src/run/loadConfigFile.js:46:32
    at process._tickCallback (internal/process/next_tick.js:68:7)

Work with `banner`

Given this config:

import babel from 'rollup-plugin-babel'
import uglify from 'rollup-plugin-uglify'

export default {
  entry: 'index.js',
  plugins: [
    babel({
      exclude: 'node_modules/**'
    }),
    uglify()
  ],
  format: 'umd',
  moduleName: 'isEmailMaybe',
  sourceMap: true,
  banner: `/**
 * @name isEmailMaybe
 * @license MIT
 * @copyright (c) 2016 Kent C. Dodds
 * @author Kent C. Dodds <[email protected]> (kentcdodds.com)
 */`
}

The my licensing comment (from the banner) will be removed. I believe that by default uglify keeps this around, but with the current implementation of this plugin, it is removed.

Name collision

Hello.
We have a name collision when uglifying rolled up code. This a snippet, causing problems:

let { cellElement, row, record, value } = renderData,
    html                                = '',
    gridMeta                            = record.instanceMeta(renderData.grid),
    cls                                 = '';

cellElement.className = 'b-grid-cell ' + me.internalCellCls;

if (me.originalRenderer) {
    let rendererHtml = me.originalRenderer(renderData);
    value = rendererHtml === false ? cellElement.innerHTML : rendererHtml;
}

if (gridMeta.parentFor >= 0) {
    row.addCls && row.addCls('b-tree-parent-row');
    cellElement.classList.add('b-tree-parent-cell');
}

It gets uglified to (I took liberty to add some spaces for readability):

let{cellElement:r,row:n,record:o,value:i}=e,s="",a=o.instanceMeta(e.grid),l=""; // first n
if(
  r.className="b-grid-cell "+t.internalCellCls,
  t.originalRenderer) {
    let n=t.originalRenderer(e);i=!1===n?r.innerHTML:n // second n
  }

if(a.parentFor>=0){n.addCls&&n.addCls("b-tree-parent-row"),r.classList.add("b-tree-parent-cell")

If you look closely, there are 2 n variables declared. While this is allowed with let, it causes troubles when this code gets processed by javascript-obfuscator, which replaces let with var.

Can you please look into that and maybe avoid such possible collisions?

no default export

such a shame.. i'm automatically importing all the NPM modules to my gulp and those without default export don't work. this is the first time (in many years) I see a module without a default export

would you mind making it so? :)

Working with uglify harmony branch

To get it working with the Harmony branch of UglifyJS you need to install the harmony branch via NPM (note the npm docs are out of date on this)

npm install --save-dev uglify-js-harmony

and specify the harmony branch in your Rollup config

import { rollup } from 'rollup';
import uglify from 'rollup-plugin-uglify';
import { minify } from 'uglify-js-harmony';

rollup({
    entry: 'main.js',
    plugins: [
        uglify({}, minify)
    ]
});

Error transforming bundle with 'uglify' plugin

I am receiving the following error when I attempt to add the uglify plugin into my Rollup chain:

[!] (uglify plugin) Error: Error transforming bundle with 'uglify' plugin: Unexpected token: punc (()

The rest of the error makes it unclear if this is ultimately a Rollup or Uglify issue:

Error: Error transforming bundle with 'uglify' plugin: Unexpected token: punc (()
at error (/Users/pappas/Repositories/fleet/node_modules/rollup/dist/rollup.js:185:14)
at Promise.resolve.then.then.catch.err (/Users/pappas/Repositories/fleet/node_modules/rollup/dist/rollup.js:9217:5)
at

However, I only run into an issue with uglify in the plugins chain.

My config currently looks like the following:

import vue from 'rollup-plugin-vue';
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import sass from 'rollup-plugin-sass';
import sassLint from 'rollup-plugin-sass-lint';
import uglify from 'rollup-plugin-uglify';
import serve from 'rollup-plugin-serve';

export default {
  name: 'Fleet',
  input: 'src/fleet-vue/main.js',
  globals: {
    vue: 'Vue',
    lodash: '_',
    'fuse.js': 'Fuse'
  },
  output: [
    {
      file: 'dist/js/fleet-vue.js',
      format: 'umd',
    },
    {
      file: 'dist/js/fleet-vue.esm.js',
      format: 'es'
    },
    {
      file: 'dist/js/fleet-vue.common.js',
      format: 'cjs'
    },
  ],
  plugins: [
    serve({
      open: true,
      verbose: true,
      contentBase: ['dist', '_site']
    }),
    sassLint({
      configFile: '.sass-lint.yml',
      failOnError: true
    }),
    resolve({
      jsnext: true,
      module: true
    }),
    commonjs(),
    vue(),
    sass({
      output: 'dist/css/fleet.css',
      options: {
        // node-sass options
      }
    }),
    uglify()
  ]
};

TypeError: uglify is not a function

Hi. Using the following gives an error in the cli: TypeError: uglify is not a function

import uglify from 'rollup-plugin-uglify';
export default {
  input: 'src/js/main.js',
  output: {
    file: 'build/js/bundle.js',
    format: 'cjs', // immediately-invoked function expression — suitable for <script> tags
    sourcemap: true
  },
  plugins: [
    uglify()
  ]  
};

This fixes the issue though:
uglify.uglify()

Not sure if I've done something wrong or if there is a defect with the version I'm using ("version": "4.0.0").

Thanks

Cannot read property 'length' of undefined

Hey,

I updated to 2.0.0 and updated the reference to uglify-es in my rollup config, but i get the following error and have had to downgrade to bundle successfully. Is there something else i need to do?

Cannot read property 'length' of undefined

Here's my rollup config:

// Rollup plugins
import eslint from 'rollup-plugin-eslint';
import babel from 'rollup-plugin-babel';
import uglify from 'rollup-plugin-uglify';
import { minify } from 'uglify-es';

export default {
    entry : './scripts/application/application.js',
    dest : './scripts/application/application.min.js',
    format : 'iife',
    plugins: [
        eslint({
            "env": {
                "browser": true,
                "es6": true
            },
            "extends": "eslint:recommended",
            "parserOptions": {
                "sourceType": "module"
            },
            "rules": {
                "linebreak-style": [
                    "error",
                    "unix"
                ],
                "semi": [
                    "warn",
                    "always"
                ],
                "no-unused-vars": "off",
                "no-undef": "off",
                "no-console": "off"
            }
        }),
        babel({
            exclude : ['./node_modules/**', './scripts/parties/**'],
            presets : [[
                "env", {
                    "targets" : {
                        "browsers" : ["> 1%", "last 2 versions", "Firefox ESR", "not ie_mob <= 12"]
                    },
                    "modules" : false
                }
            ]],
            plugins : [
                "external-helpers"
            ]
        }),
        uglify({
            screwIE8 : true
        }, minify)
    ]
};

Also here's my package json:

{
  "name": "project",
  "version": "1.0.0",
  "author": "Team",
  "devDependencies": {
    "autoprefixer": "^7.1.1",
    "babel-plugin-external-helpers": "^6.22.0",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-preset-env": "^1.4.0",
    "browser-sync": "^2.18.11",
    "node-sass": "^4.5.3",
    "onchange": "^3.2.1",
    "parallelshell": "^2.0.0",
    "postcss-cli": "^4.0.0",
    "rollup": "^0.41.6",
    "rollup-plugin-babel": "^2.7.1",
    "rollup-plugin-eslint": "^3.0.0",
    "rollup-plugin-uglify": "^2.0.0",
    "rollup-watch": "^3.2.2",
    "stylelint": "^7.10.1",
    "uglify-es": "^3.0.9"
  },
  "stylelint": {
    "rules": {
      "indentation": 4,
      "number-leading-zero": null
    }
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "Firefox ESR",
    "iOS 9",
    "not ie_mob <= 12",
    "not ie <= 10",
    "not blackberry <= 7"
  ],
  "scripts": {
    "lint-scss": "stylelint ./styles/**/*.scss --cache --syntax scss",
    "scss": "node-sass --omit-source-map-url --recursive --output-style compressed --output ./styles ./styles",
    "autoprefixer": "postcss --use autoprefixer --replace ./styles/style.css --no-map",
    "build:css": "yarn run lint-scss --silent | yarn run scss --silent | yarn run autoprefixer --silent",
    "build:js": "rollup --config",
    "serve": "browser-sync start --https --no-notify --proxy 'right.lance' --files './styles/**/*.css, ./views/**/*.php, ./**/*.html, !node_modules/**/*.html'",
    "watch:css": "onchange './styles/**/*.scss' -- yarn run build:css --silent",
    "watch:js": "rollup --config --watch",
    "watch:all": "parallelshell 'yarn run serve --silent' 'yarn run watch:css --silent' 'yarn run watch:js --silent'",
    "postinstall": "yarn run watch:all --silent",
    "go": "yarn run postinstall --silent"
  }
}

Thanks!

support unminified and minified

Hi, thanks for this plugin!!
Is it possible to have 2 files, the original and the minified version in the same rollup call, ideally both with sourcemaps?

Error: Farm is ended, no more calls can be done to it

rollup.config.js

const resolve = require('rollup-plugin-node-resolve')
const commonjs = require('rollup-plugin-commonjs')
const Eslint = require('rollup-plugin-eslint')
const babel = require('rollup-plugin-babel')
const Uglify = require('rollup-plugin-uglify')
const pkg = require('./package.json')

const banner =
  '/*!\n' +
  ' * Build version v' + pkg.version + '\n'  +
  ' */'

const isProduction = process.env.NODE_ENV === 'production'

module.exports = {
  input: 'src/index.js',
  output: [
    {
      // window.Marquee
      name: 'Marquee',
      file: isProduction ? 'dist/index.min.js' : 'dist/index.js',
      format: 'umd',
      banner: banner,
      sourcemap: false
    },
    { file: 'dist/index.cjs.js', format: 'cjs', banner: banner },
    { file: 'dist/index.esm.js', format: 'esm', banner: banner },
    { file: 'dist/index.amd.js', format: 'amd', banner: banner },
    { file: 'dist/index.iife.js', format: 'iife', name: 'Marquee', banner: banner }
  ],
  plugins: [
    Eslint.eslint({
      exclude: ['node_modules/**']
    }),
    resolve(),
    commonjs(),
    babel({
      exclude: 'node_modules/**'
    }),
    (isProduction && Uglify.uglify())
  ]
}

Error:

> rollup -c --environment NODE_ENV:production


src/index.js → dist/index.min.js, dist/index.cjs.js, dist/index.esm.js, dist/index.amd.js, dist/index.iife.js...
[!] (uglify plugin) Error: Farm is ended, no more calls can be done to it
Error: Farm is ended, no more calls can be done to it
    at exports.default.end (D:\work\marqueejs\node_modules\jest-worker\build\index.js:166:13)
    at Object.generateBundle (D:\work\marqueejs\node_modules\rollup-plugin-uglify\index.js:38:19)
    at D:\work\marqueejs\node_modules\rollup\dist\rollup.js:21962:25
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

comments for licensing

Hey Bogdan, regarding what you've mentioned in README, I was wondering. a code can have thousands upon thousands of comments. check each for the single one which is your license seems to me harmful for performance.

Wouldn't it be better to pass an option to leave alone on the first comment?
The first comment is almost always the license comment.

Error transforming bundle with 'uglify' plugin

I have an Angular 2 sample app that's bundle up with Rollup, but it throws an error when using this plugin. It says

Error transforming bundle with 'uglify' plugin: SyntaxError: Unexpected token: name (AppComponent).

This is how my rollup.config.s looks like


import rollup from 'rollup'
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify';

export default {
    entry: 'dist/app/main.js',
    dest: 'dist/build.js', // output a single application bundle
    sourceMap: false,
    format: 'iife',
    plugins: [
        nodeResolve({ jsnext: true, module: true }),
        commonjs({
            namedExports: {
                // left-hand side can be an absolute path, a path 
                // relative to the current directory, or the name 
                // of a module in node_modules 
                'node_modules/primeng/primeng.js': ['DialogModule']
            },
            include: ['node_modules/rxjs/**', 'node_modules/primeng/**']
        }),
        uglify()
    ]
}

Switch to uglify-es?

Thanks for your great work on this plugin.

Have you seen uglify-es? It is created by the same author as uglify-js (it is even in the same repo) and it supports es6+. You can find the documentation here. Maybe it makes sense to switch to this package to enable es6+ Syntax?

Cannot preserve first comment

I am using a simple gulp configuration trying to automate logerr deploying:

const gulp = require('gulp')
const $ = require('gulp-load-plugins')()
const rollupPlugins = require('rollup-load-plugins')()
gulp.task('default', () => {
  return gulp.src('logerr.js')
    .pipe($.sourcemaps.init())
    .pipe($.rollup({
      entry: 'logerr.js',
      sourceMap: true,
      plugins: [
        rollupPlugins.babel(),
        rollupPlugins.uglify({
          output: {
            comments: (node, comment) => {
              return comment.line === 1
            }
          }
        })
      ]
    }))
    .pipe($.rename({
      suffix: '.min'
    }))
    .pipe($.sourcemaps.write('.'))
    .pipe(gulp.dest('./'))
})

All is ok but I want to preserve first “banner” comment from logerr.js:

/**
 * logerr
 *
 * @category   logerr
 * @author     Vaibhav Mehta <[email protected]>
 * @copyright  Copyright (c) 2016 Vaibhav Mehta <https://github.com/i-break-codes>
 * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
 * @version    1.2 Stable
 */

But I cannot. This comment just disappears after rollup-plugin-uglify + rollup-plugin-babel even if I set { output: { comments: true } }. All comments is preserved but not first.

If I remove rollup-plugin-babel but use rollup-plugin-uglify, behaviour is expected: saved only first comment with my config.

If I remove rollup-plugin-uglify but use rollup-plugin-babel, behaviour is expected: first comment not removed.

Cannot Read Property 'end' of undefined

import resolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import { uglify } from 'rollup-plugin-uglify'
import commonjs from 'rollup-plugin-commonjs'

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/index.js',
    format: 'umd',
    name: 'Name',
    globals: {
      react: 'React',
    },
  },
  plugins: [
    resolve(),
    babel({
      runtimeHelpers: true,
      exclude: 'node_modules/**',
      plugins: [
        'external-helpers',
      ],
    }),
    commonjs({
      namedExports: {
        'stylis-rule-sheet': ['stylisRuleSheet'],
      },
    }),
    uglify(),
  ],
  external: ['react'],
}

When I run this I get "TypeError: Cannot read property 'end' of undefined"

Unexpected token: keyword (const)

After upgrade to 2.0.1 from 1.0.2 my build stops working.

🚨   (uglify plugin) Error: Error transforming bundle with 'uglify' plugin: Unexpected token: keyword (const)

I am back to 1.0.2 now.

Keep a CHANGELOG?

I saw version 2.0.x was released and went to look for a changelog but couldn't find it. Given it's a major I should assume breakage but how would I know what to fix? Will it support the move from uglify-js-harmony to uglify-es now that the prior is deprecated? Not sure without digging through the code and your mind.

I've provided some information to help easily create changelogs in the link below. It would be great to have one when taking upgrades to save digging through the source.

speedtracker/speedtracker#56 (comment)

See also: http://keepachangelog.com/en/0.3.0/

5.0 roadmap

  • change transformBundle hook to renderChunk
  • rename sourceMap option to sourcemap to be consistent with rollup api
  • forbid using sourceMap as unknown option
  • add worker to process each chunk in separate threads
  • make same changes in terser
  • add points in readme

support for rollup 2.0

rollup-plugin-uglify:

  "peerDependencies": {
    "rollup": ">=0.66.0 <2"
  },

how can I use rollup-plugin-uglify with rollup 2.x?

(uglify plugin) Error: `sourcemap` is not a supported option

Hi!

When running rollup using the rollup-plugin-uglify I get an error:

(uglify plugin) Error: sourcemap is not a supported option

It seems to have to do with an update to the serialize-javascript plugin where they no longer remove keys that has an undefined value. Hence the sourcemap (all lowercase) option is passed to uglify that throws an error since that is an invalid option (should be camelcased).

This error also happens for the numWorkers option.

Rollup v1

Hey!

I like this plugin, it would be nice to have this updated for rollup v1.

NPM is warning about out of range peer dependency
npm WARN [email protected] requires a peer of rollup@>=0.66.0 <1 but none is installed. You must install peer dependencies yourself.

Sourcemaps from TypeScript?

I'm using this plugin with others in this order:
rollup-plugin-css-only
rollup-plugin-sourcemaps
rollup-plugin-replace
rollup-plugin-resolve({jsnext: true,main: true})
rollup-plugin-commonjs
rollup-plugin-uglify

But this issue is without uglify I have TypeScript sourcemaps that come across and work normally, but when uglify is added the sourcemaps don't have the uglified variables, etc. in the debugger. The lines still correspond, but when highlighting variables to see their value it says they are undefined since they've been renamed by uglify.

I seem to be failing at configuring uglify to provide sourcemaps, is there an order or option I'm missing here that would allow me to uglify but use the typescript sourcemaps?

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.