Code Monkey home page Code Monkey logo

terser-brunch's Introduction

terser-brunch

Adds Terser support to Brunch.

The plugin will minify your JavaScript files. Supports modern language features.

Previously known as uglify-js-brunch.

Usage

Install the plugin via npm with npm install --save-dev terser-brunch.

To specify Terser options, use config.plugins.terser object, for example:

module.exports = {
  // ...
  plugins: {
    terser: {
      mangle: false,
      compress: {
        global_defs: {
          DEBUG: false,
        },
      },
    },
  },
};

Joined files can be ignored and be passed-through, using ignored option:

module.exports = {
  plugins: {
    terser: {
      ignored: /dont-minimize\.js/,
    },
  },
};

License

The MIT License (MIT)

terser-brunch's People

Contributors

amitayd avatar berniesumption avatar csmosx avatar denysdovhan avatar es128 avatar goshacmd avatar lydell avatar paulmillr avatar plepers avatar shinnn avatar shvaikalesh 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  avatar  avatar  avatar  avatar

terser-brunch's Issues

Wrong minified output with a jade template

Hi,
I've run into an issue where my templates.js has bad syntax when i use brunch b -m.

I have a file called templates.js which is my generated jade templates, and if I call uglify on this, it minifies fine (with the default settings)...

Is brunch doing something different that would cause this behavior to be different?

The un-compressed templates file is here: https://dl.dropbox.com/u/120257/templates.js

Cheers,
Chris

Copyright notice is always stripped

I tried the following, but my copyright notice is always stripped in the minified app.js.

In application.coffee I tried adding ! and @license to the comment:

###!
@license app.js
Copyright 2014 blah...
###

In brunch-config.coffee I tried the following options:

exports.config:
  plugins:
    uglify:
      comments: 'all'
      preamble: '# hello'

Arrow functions / ES6 error ?

Getting below error for below code:

CBM-Demo>brunch build --production
31 Jul 22:02:37 - error: JS minification failed on www/js/app.js: Unexpected token: operator (>) (line: 216, col: 64, pos: 5307)

Error
    at new JS_Parse_Error (\node_modules\uglify-js\lib\parse.js:196:18)
    at js_error (\node_modules\uglify-js\lib\parse.js:204:11)
    at croak (\node_modules\uglify-js\lib\parse.js:680:9)
    at token_error (\node_modules\uglify-js\lib\parse.js:688:9)

code sample

ages[0] = _.chain(source).map('age1').map(x => { return parseInt(x) }).filter(x => { return !isNaN(x) && x > 0; }).value();
ages[1] = _.chain(source).map('age2').map(x => { return parseInt(x) }).filter(x => { return !isNaN(x) && x > 0; }).value();

npm prepublish did not run

Strangely, the prepublish script did not run when I just did git release 1.7.3. I subsequently did npm run-script prepublish, but I downloaded the latest version of the module from the npm registry and saw that the compiled lib/index.js was an old version. I then did npm publish --force to correct this.

This may have impacted other prior releases as well. I'm not quite sure which version of the compiled js I was looking at, but I'm pretty sure it did not include the 1.7.2 changes.

@paulmillr any idea what's going on here?

Supporting uglify-es?

Hello,

What about supporting ES6, e.g. including uglify-es?

This would help using other libs that require ES6, e.g. @yaga/leaflet-ng2.

Thanks, JC

Fatal error when setting uglify.ignored

I want Uglify to ignore app.js but minify vendor.js and lib.js (app.js will be run through Closure using after-brunch)

However, using config.plugins.uglify.ignored = /app.js/ gives me an error when I do brunch build --production

error checking ignores files to uglify:TypeError: Object {"version":3, "file":"../game/js/app.js", "sources":["app/source1.js", "app/source2.js"], "names":[], "mappings":";;;;;... ...AACA, "sourcesContent":["....;"]} has no method 'toJSON'

I am using"
uglify-js-brunch v1.7.7
brunch v1.7.13 (I have in fact also installed brunch using npm install -g brunch/brunch which should be a more up to date version?)

Relevant bits of config:

exports.config =
files:
javascripts:
joinTo:
'js/app.js': /^app/
'js/lib.js': /^bower_components/
'js/vendor.js': /^vendor/

plugins:
uglify:
mangle: true
compress: true
ignored: /app.js/

rename minjs

Possible to rename the app.js minifyed like app.min.js ?

Optimizing of ../priv/static/js/app.js failed. L12175:31 SyntaxError: Unexpected token: operator (>)

Able to build this project (that uses react-native-web) in dev.

But when I run yarn deploy, I get the entitled error.

Looked around online to no avail...


OK, ran PORT=4000 MIX_ENV=prod mix phx.server and my app was working fine (NOT getting the error from the Phoenix deploy guide).

So any idea why I'm getting 404s for all static assets when I actually deploy? My assumption is because of this build error...

JS minify failed on public/javascripts/app.js: TypeError: Cannot assign to read only property 'except' of [object Object]

When using uglify-js-brunch with the following configuration (from config.coffee):

exports.config =
  plugins:
    uglify:
      mangle:
        except: [ "require" ]

With the following command line:

brunch build --optimize

I get the following error.

error: JS minify failed on public/javascripts/app.js: TypeError: Cannot assign to read only property 'except' of [object Object]

I'm using node v0.10.5, brunch 1.6.3, and uglify-js-brunch 1.5.1.

Uglify breaks RickShaw

Hi,

it seems that Uglify doesn't work very well with D3JS (v3.0) and also with RickShaw.

When uglified there is an error for RickShaw:

"Uncaught TypeError: undefined is not a function "

Best regards

Weird errors when using 'brunch watch'

Running brunch build works fine, but when running brunch watch it executes the initial compilation well but when I edit a file and save it brunch throws errors.

When I edit a CSS file I get this error:

R:\project\node_modules\uglify-js-brunch\lib\index.js:50
        data: optimized.code
                       ^
TypeError: Cannot read property 'code' of undefined
    at UglifyMinifier.module.exports.UglifyMinifier.optimize (R:\project\node_modules\uglify-js-brunch\lib\index.js:50:24)
    at R:\project\node_modules\uglify-js-brunch\lib\index.js:3:59
    at generate (C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\lib\fs_utils\generate.js:253:12)
    at gen (C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\lib\fs_utils\write.js:93:14)
    at C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\node_modules\async-each\index.js:16:7
    at Array.forEach (native)
    at each (C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\node_modules\async-each\index.js:15:11)
    at Object.module.exports.write (C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\lib\fs_utils\write.js:95:12)
    at C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\lib\watch.js:266:23
    at FileList.<anonymous> (C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\lib\watch.js:523:18)
    at FileList.EventEmitter.emit (events.js:92:17)
    at null._onTimeout (C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\lib\fs_utils\file_list.js:115:17)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

When I edit a JS file I get this error:

R:\project\node_modules\uglify-js-brunch\lib\index.js:52
      callback(error, result || data);
      ^
TypeError: string is not a function
    at UglifyMinifier.module.exports.UglifyMinifier.optimize (R:\project\node_modules\uglify-js-brunch\lib\index.js:52:7)
    at R:\project\node_modules\uglify-js-brunch\lib\index.js:3:59
    at generate (C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\lib\fs_utils\generate.js:253:12)
    at gen (C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\lib\fs_utils\write.js:93:14)
    at C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\node_modules\async-each\index.js:16:7
    at Array.forEach (native)
    at each (C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\node_modules\async-each\index.js:15:11)
    at Object.module.exports.write (C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\lib\fs_utils\write.js:95:12)
    at C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\lib\watch.js:266:23
    at FileList.<anonymous> (C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\lib\watch.js:523:18)
    at FileList.EventEmitter.emit (events.js:92:17)
    at null._onTimeout (C:\Users\myusername\AppData\Roaming\npm\node_modules\brunch\lib\fs_utils\file_list.js:115:17)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

After errors I have to rerun brunch watch because it gets killed by the error, although it doesn't make sense because on the next run it crashes again, always.

Any ideas? Thanks!

TypeError in NPM when using Brunch on Heroku from UglifyMinifier.optimize

I've recently upgraded Brunch and related libraries (e.g., uglify-js-brunch) to 1.7.x. When pushing to Heroku, I get the error pasted below. Any clues on how I can go about fixing this?

If I remove uglify-js-brunch from my package.json, then it'll work on Heroku.

Thanks!

-----> Installing dependencies

       > [email protected] postinstall /tmp/build_d24a4120-fea7-4048-bddb-66be19b378f0
       > brunch build --production


       /tmp/build_d24a4120-fea7-4048-bddb-66be19b378f0/node_modules/uglify-js-brunch/lib/index.js:48
               data: optimized.code
                              ^
       TypeError: Cannot read property 'code' of undefined
           at UglifyMinifier.module.exports.UglifyMinifier.optimize (/tmp/build_d24a4120-fea7-4048-bddb-66be19b378f0/node_modules/uglify-js-brunch/lib/index.js:48
:24)
           at /tmp/build_d24a4120-fea7-4048-bddb-66be19b378f0/node_modules/brunch/lib/fs_utils/generate.js:220:25
           at fn (/tmp/build_d24a4120-fea7-4048-bddb-66be19b378f0/node_modules/brunch/node_modules/async-waterfall/index.js:19:24)
           at Object._onImmediate (/tmp/build_d24a4120-fea7-4048-bddb-66be19b378f0/node_modules/brunch/node_modules/async-waterfall/index.js:58:22)
           at processImmediate [as _immediateCallback] (timers.js:330:15)

       npm ERR! [email protected] postinstall: `brunch build --production`
       npm ERR! Exit status 8
       npm ERR!
       npm ERR! Failed at the [email protected] postinstall script.
       npm ERR! This is most likely a problem with the xxxx package,
       npm ERR! not with npm itself.
       npm ERR! Tell the author that this fails on your system:
       npm ERR!     brunch build --production
       npm ERR! You can get their info via:
       npm ERR!     npm owner ls xxxx
       npm ERR! There is likely additional logging output above.
       npm ERR! System Linux 3.8.11-ec2
       npm ERR! command "/tmp/build_d24a4120-fea7-4048-bddb-66be19b378f0/vendor/node/bin/node" "/tmp/build_d24a4120-fea7-4048-bddb-66be19b378f0/vendor/node/bin/np
m" "install" "--production"
       npm ERR! cwd /tmp/build_d24a4120-fea7-4048-bddb-66be19b378f0
       npm ERR! node -v v0.10.22
       npm ERR! npm -v 1.3.14
       npm ERR! code ELIFECYCLE
       npm ERR!
       npm ERR! Additional logging details can be found in:
       npm ERR!     /tmp/build_d24a4120-fea7-4048-bddb-66be19b378f0/npm-debug.log
       npm ERR! not ok code 0

Brunch 2.0 support

This plugin doesn't work correctly under the current Brunch version (at this time, 2.0.2).

I'm new to Brunch, but from some exploration it looks like the plugin API has changed significantly- for example, the args argument being passed to the optimize function is now a promise instead of an object.

Plugin not processing

Hello,

I'm running into a problem: I recently wanted to compress my JS files so I installed the plugin. Apparently, it's not working for some reason (same thing with brunch-clean-css). Could you please open my eyes on what I am doing wrong, please?

Here is my package.json

{
  "dependencies": {
    "javascript-brunch": "1.7.1",
    "css-brunch": "1.7.0",
    "coffee-script-brunch": "1.8.0",
    "stylus-brunch": "1.8.0",
    "jade-brunch": "1.8.1",
    "uglify-js-brunch": "1.7.7",
    "clean-css-brunch": "1.7.1",
    "coffeelint-brunch": "1.7.0"
  }
}

And my config.coffee:

module.exports.config =
    files:
        javascripts:
            joinTo:
                'javascripts/app.js': /^app/
                'javascripts/vendor.js': /^vendor/
            order:
                # Files in `vendor` directories are compiled before other files
                # even if they aren't specified in order.
                before: [
                    'vendor/scripts/jquery-1.11.0.js'
                    'vendor/scripts/underscore-1.5.2.js'
                    'vendor/scripts/backbone-1.1.0.js'
                    'vendor/scripts/backbone.babysitter.js'
                    'vendor/scripts/backbone.projections.js'
                ]

        stylesheets:
            joinTo: 'stylesheets/app.css'
            order:
                before: ['vendor/styles/normalize.css']
                after: ['vendor/styles/helpers.css']

        templates:
            defaultExtension: 'jade'
            joinTo: 'javascripts/app.js'

    plugins:
        uglify:
            mangle: false
            compress:
                global_defs:
                    DEBUG: false
        cleancss:
            keepSpecialComments: 0
            removeEmpty: true

I think this could come from the fact I'm using Coffee to write JS and Stylus to write CSS (for clean-css' case) but I didn't manage to 1°) be 100% sure it's the reason 2°) found a solution for that.

Thank you in advance!

Can't generate a production build

I followed the instructions present in the README of this repo, but I still can't generate a production ready build. I get the following warning: It looks like you're using a minified copy of the development build of React. When deploying React apps to production, make sure to use the production build which skips development warnings and is faster. See https://fb.me/react-minification for more details.

Here is my entire webpack.config.js

`
const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
inject: 'body'
});

module.exports = {
entry: './src/index.jsx',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'views/panel')
},
plugins: {
uglify: {
mangle: false,
compress: {
global_defs: {
DEBUG: false
}
}
}
},
module: {
loaders: [
{
test: /.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /.css$/,
loader: "style-loader!css-loader"
}
],
rules: [
{
test: /.jsx?$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader"
},
{
loader: "eslint-loader",
options: {
fix: true
}
}
]
},
{
test: /.css$/,
use: [ 'style-loader', 'css-loader' ]
},
{
test: /.(png|woff|woff2|eot|ttf|svg)(?v=[0-9].[0-9].[0-9])?$/,
loader: 'url-loader'
}
],
},
devtool: 'inline-source-map',
plugins: [
HtmlWebpackPluginConfig,
new UglifyJSPlugin()
]
};`

Error when using source maps

When setting optimize = true and sourceMaps = true I'm getting an error

./node_modules/brunch/lib/fs_utils/generate.js:199
          json = optimizedMap.toJSON();

TypeError: Object {"vers.....MAAO,GAGX,MAAO"} has no method 'toJSON'

This is for the latest version: 1.7.6

Fail to compress js builded from typescript

I made a little plugin to build typescript with brunch (https://www.npmjs.com/package/brunch-typescript). For a personal project, I want build and uglify but I have an error with compression. So strange, because when I execute manually uglify-js, I don't have fail.

'use strict';

exports.config = {
    paths: {
        'public': 'dist',
        'watched': [
            'src'
        ]
    },
    files: {
        javascripts: {
            joinTo: {
                'dest.js': 'my/source.ts'
            }
        },
    },
    plugins: {
        uglify: {
            mangle: true
        }
    }
};

My package.json :

{
    "dependencies": {
        "brunch": "1.8.*",
        "brunch-typescript": "1.5.*",
        "uglify-js-brunch": "1.7.*"
    }
}

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.