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

Setting uglifyJS options #26

Open
DylanPiercey opened this issue Dec 14, 2014 · 13 comments
Open

Setting uglifyJS options #26

DylanPiercey opened this issue Dec 14, 2014 · 13 comments

Comments

@DylanPiercey
Copy link

How can one send options to uglify js with this transform?

Such as:

{
    mangle: true,
    compress: {
        sequences: true,
        dead_code: true,
        conditionals: true,
        booleans: true,
        unused: true,
        if_return: true,
        join_vars: true,
        drop_console: true
}
@hughsk
Copy link
Owner

hughsk commented Jan 16, 2015

From the CLI, you can use subarg syntax :)

browserify index.js -t [ uglifyify --mangle --compress [ --sequences --dead_code --booleans ] ]

Or if working with browserify as a module:

var browserify = require('browserify')
var bundler = browserify('index.js')

bundler.transform({
  mangle: true,
  compress: {
    sequences: true,
    dead_code: true
    booleans: true
  }
}, 'uglifyify')

@AsaAyers
Copy link

Do you know if there's a set of configs that will only trim dead code? I'd like to combine this with envify to remove some requires, but something just doesn't seem right about uglifying the code in the bundle. And I'm already running uglify on the final output.

@hughsk
Copy link
Owner

hughsk commented Jan 21, 2015

@AsaAyers my guess would be:

{
  mangle: false,
  compress: {
    dead_code: true
  }
}

Give that a shot and see if it works :)

@AsaAyers
Copy link

It still collapses everything onto one line. Thanks for trying though :)

I tried looking through the list of transforms again and I think unreachable-branch-transform is really what I'd prefer to use.

@naorye
Copy link

naorye commented Jan 28, 2015

@hughsk
I am executing browserify with the following arguments:
bundler.transform(uglifyify, { global: true, mangle: true, compress: { sequences: true, dead_code: true, booleans: true } });

and I get the same code as if I executed:
bundler.transform(uglifyify, { global: true });

I think there is a problem.

@weilu
Copy link
Collaborator

weilu commented Feb 4, 2015

@naorye a bunch of options are set to true by default, including compress and mangle. Try setting them to false you should see different output.

@naorye
Copy link

naorye commented Feb 4, 2015

@weilu You right. The thing is that after using uglifyify, I get several uglyfied files concatenated into one file with a lot of line breaks. So I am using gulp-uglify after browserify done it's work. Is it the right way to do it?

@weilu
Copy link
Collaborator

weilu commented Feb 5, 2015

You shouldn't need to run it through gulp-uglify again. You are not the first person to report the line breaks problem. Unfortunately I don't have the same issue with my package. Is it possible for you to note down the exact steps to reproduce the line break issue?

@ribeiroct
Copy link

+1 With the line-break problem

@yoshuawuyts
Copy link
Collaborator

@ribeiroct +1's are generally not as useful as a step-by-step repro of what causes the issue for you. Would you mind posting one so we can help resolve this issue? Thanks!

@ribeiroct
Copy link

I'm using it as follows:

    browserify -d -t babelify -g [ uglifyify --no-sourcemap] files/*.jsx -o bundle.js

Browserify version: 9.0.3
Uglifyify version 3.0.1

Breaklines seem to be introduced after some of the function opening brackets.

I'm using it on a reactjs project.

To solve it i'm doing another pass with uglifyjs in the end. Can babelify be having an effect on the process? I'm not sure.

@weilu
Copy link
Collaborator

weilu commented May 30, 2015

@ribeiroct @naorye I don't have your source code so I'm not sure how to reproduce this. Can either of you give me the smallest reproducible source before bundle?

@naorye
Copy link

naorye commented May 31, 2015

This is my bundle creation code:

    var bundleEntries = [ './a/client.js', './b/client.js', './c/client.js' ],
        bundleOutputs = [ './build/a/client.js', './build/b/client.js', './build/c/client.js' ],
        commonOutput = './build/bundle.js',
        b = null,
        // The following runs scriptBuild() over all the returned scripts
        write = filesWriter(scriptBuild, 1 + bundleOutputs.length, done)

        params = { // Preare params
            entries: bundleEntries, // All frames entries
            transform: [ [ envify, { global: true } ] ],
            extensions: [ '.jsx' ] // Add jsx for the module lookup machinery
        };

    if (process.env.DISTRIBUTION) {
        params.transform.push([ 'uglifyify', { global: true, sourcemap: process.env.WATCH } ]);
    }

    if (process.env.WATCH) {
        objectAssign(params, {
            debug: true, // Gives us sourcemaps
            cache: {}, // Requirement of watchify
            packageCache: {}, // Requirement of watchify
            fullPaths: true// Requirement of watchify
        });

        b = browserify(params);
        b = watchify(b);
        b.on('update', bundle);
    } else {
        b = browserify(params);
    }

    bundle();

    function bundle() {
        return b
            .plugin('factor-bundle', { outputs: bundleOutputs.map(write) })
            .on('error', function(err) { console.error(err) })
            .bundle()
            .pipe(write(commonOutput));
    }

    function scriptBuild(stream, filePath, dirname, basename) {
        if (process.env.DISTRIBUTION) {
            stream = stream
                .pipe(uglify())
                .pipe(rev())
                .pipe(gulp.dest(dirname))
                .pipe(rev.manifest());
        }
        return stream.pipe(gulp.dest(dirname));
    }

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

No branches or pull requests

7 participants