Coder Social home page Coder Social logo

Setting uglifyJS options about uglifyify HOT 13 OPEN

hughsk avatar hughsk commented on June 19, 2024
Setting uglifyJS options

from uglifyify.

Comments (13)

hughsk avatar hughsk commented on June 19, 2024 4

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')

from uglifyify.

AsaAyers avatar AsaAyers commented on June 19, 2024 1

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.

from uglifyify.

ribeiroct avatar ribeiroct commented on June 19, 2024 1

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.

from uglifyify.

hughsk avatar hughsk commented on June 19, 2024

@AsaAyers my guess would be:

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

Give that a shot and see if it works :)

from uglifyify.

AsaAyers avatar AsaAyers commented on June 19, 2024

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.

from uglifyify.

naorye avatar naorye commented on June 19, 2024

@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.

from uglifyify.

weilu avatar weilu commented on June 19, 2024

@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.

from uglifyify.

naorye avatar naorye commented on June 19, 2024

@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?

from uglifyify.

weilu avatar weilu commented on June 19, 2024

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?

from uglifyify.

ribeiroct avatar ribeiroct commented on June 19, 2024

+1 With the line-break problem

from uglifyify.

yoshuawuyts avatar yoshuawuyts commented on June 19, 2024

@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!

from uglifyify.

weilu avatar weilu commented on June 19, 2024

@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?

from uglifyify.

naorye avatar naorye commented on June 19, 2024

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));
    }

from uglifyify.

Related Issues (20)

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.