Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uglifier #75

Closed
pgherveou opened this issue Sep 9, 2011 · 4 comments
Closed

uglifier #75

pgherveou opened this issue Sep 9, 2011 · 4 comments

Comments

@pgherveou
Copy link

I am trying to get the uglifier working on my prod env this the code I wrote
can you tell me what's wron in it ?

var browserify  = require('browserify')
  , uglify      = require('uglify-js')

var b = browserify({
    require : ['./js/home.js']
  , mount   : "/home.js"
});

...

if (env == "production") {
        b.register(uglify); 
}
@itay
Copy link
Contributor

itay commented Sep 9, 2011

This is the code I use to get uglify-js to work for me:

var bundle = browserify({
    entry: "browser_entry.js",
    filter: function(code) {
        if (cmdline.options.uglify) {
            var uglifyjs = require("uglify-js"),
                parser = uglifyjs.parser,
                uglify = uglifyjs.uglify;

            var ast = parser.parse(code);
            ast = uglify.ast_mangle(ast);
            ast = uglify.ast_squeeze(ast);
            return uglify.gen_code(ast);
        }
        else {
            return code;
        }
    },
});

@pgherveou
Copy link
Author

Thks, I ended up using something similar too, I will dig into the source to check what I was doing wrong

@ghost
Copy link

ghost commented Sep 10, 2011

You should be able to just:

browserify({
    filter : env === 'production' ? require('uglify-js') : String
    /* ... */
})

@mitar
Copy link

mitar commented Feb 12, 2013

For Uglify2 I had to do:

    bundle.register('post', function (body) {
        return uglify.minify(body, {
            'fromString': true
        }).code;
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants