TrySound / rollup-plugin-uglify

Rollup plugin to minify generated bundle
MIT License
260 stars 42 forks source link

TypeError: uglify is not a function #45

Closed tomleadbettermsm closed 6 years ago

tomleadbettermsm commented 6 years ago

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

TrySound commented 6 years ago

Changelog is clear about using named export. https://github.com/TrySound/rollup-plugin-uglify/releases/tag/v4.0.0

julkue commented 6 years ago

@TrySound Please elaborate why uglify-es is no longer supported. I can't see any deprecations in uglify-es itself.

https://github.com/mishoo/UglifyJS2/tree/harmony

TrySound commented 6 years ago

https://github.com/mishoo/UglifyJS2/issues/3156 https://github.com/mishoo/UglifyJS2/issues/2447

Use terser for es6+ https://github.com/TrySound/rollup-plugin-terser

ardeshirvalipoor commented 5 years ago

Or you can change this line in the index file ('.\node_modules\rollup-plugin-uglify\index.js') from exports.uglify = uglify; to exports.default = uglify; to keep ... plugins: [ uglify() ]
...

TrySound commented 5 years ago

@ardivali I'm not gonna change the api. I think it's right. Use this

const { uglify } = require('rollup-plugin-uglify')
TrySound commented 5 years ago

or this

import { uglify } from 'rollup-plugin-uglify'
TrySound commented 5 years ago

Otherwise you need to do this ugly this

const { default: uglify } = require('rollup-plugin-uglify');
const uglify = require('rollup-plugin-uglify').default;