gruntjs / grunt-contrib-uglify

Minify files with UglifyJS.
http://gruntjs.com/
MIT License
1.48k stars 348 forks source link

Code is being sorted #271

Open mbrammer opened 9 years ago

mbrammer commented 9 years ago

When I'm running uglifier, the code in the destination file is not arranged like in the source file.

Short Example Source

function one() {}
function two() {}
function three() {}

Destination

function one() {}
function three() {}
function two() {}

Real Example Source

/* jQuery */
/*! jQuery v2.1.0 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */
[... jQuery JS library code ...]

/* jQuery UI*/
/*! jQuery UI - v1.11.2 - 2014-10-19
* http://jqueryui.com
* Includes: core.js, effect.js, effect-bounce.js
* Copyright 2014 jQuery Foundation and other contributors; Licensed MIT */
[... jQuery UI JS library code ...]

/* jBox (notifications) */
[... jBox JS library code ...]

/* Bootstrap */
/*!
 * Bootstrap v3.2.0 (http://getbootstrap.com)
 * Copyright 2011-2014 Twitter, Inc.
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 */
[... Bootstrap JS library code ...]

Destination

/* jQuery */
/*! jQuery v2.1.0 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */

/* jBox (notifications) */
[... jBox JS library code ...]

[... Some function from random lines (eg. 1482) ...]
[... Some function from random lines (eg. 927) ...]
[... Some function from random lines (eg. 3438) ...]

/*!
 * Bootstrap v3.2.0 (http://getbootstrap.com)
 * Copyright 2011-2014 Twitter, Inc.
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 */
[... jQuery JS library code ...]

/*! jQuery UI - v1.11.2 - 2014-10-19
* http://jqueryui.com
* Includes: core.js, effect.js, effect-bounce.js
* Copyright 2014 jQuery Foundation and other contributors; Licensed MIT */
[... jQuery UI JS library code ...]

My Config

uglify: {
    production: {
        options: {
            banner: '/*generated on <%= grunt.template.today("yyyy-mm-dd HH:MM:ss") %>*/\n',
            beautify: false,
            compress: {
                drop_console: true
            }
        },
        files: [{
            expand: true,
            cwd: 'js/.generated/public/',
            src: ['**/*.js'],
            dest: 'webroot/js'
        }]
    },

    development: {
        options: {
            beautify: true
        },
        files: [{
            expand: true,
            cwd: 'js/.generated/public/',
            src: ['**/*.js'],
            dest: 'webroot/js'
        }]
    }
},

Did I do something wrong or is it a bad bug?!

jamesplease commented 9 years ago

This is likely an issue with Uglify, and not this task, which is just a wrapper. Have you tried running the source through the uglify command line? Does it also resort your code?

mbrammer commented 9 years ago

Yes I have and no it doesn't sort the code. I used uglifyjs js/.generated/public/global.js -o webroot/js/global.js So the problem seems to be grunt-contrib-uglify.

jamesplease commented 9 years ago

Which version are you comparing against? The development version? If so, try turning on the beautify flag to the CLI. More generally make sure that the options are the same when you're comparing.

mbrammer commented 9 years ago

Oh sorry, forgot to mention that. No, the production is used. I have specially added beautify: false, but I didn't change anything. I just tried to turn on beautify and it's also sorted.

mbrammer commented 9 years ago

Tried a more basic config and started grunt uglify:production

uglify: {
    production: {
        files: {
            'js/global.min.grunt.js': ['js/.generated/public/global.js']
        }
    }
}

Same problem. BTW: I'm using the latest version 0.6.0 of grunt-contrib-uglify

mbrammer commented 9 years ago

@jmeas Can you reproduce this issue?

argyleink commented 8 years ago

+1, i'm experiencing this as well.

prod:
    options:
      banner:     "<%= banner %>"
      screwIE8:   true
      compress:   drop_console: true
    files: 
      "<%= dirs.build %>/js/app.js":"<%= app.js %>"

the array of app.js is not respected, breaking the production minified code. i havent tried uglify from the command line, but will try now.

pythdasch commented 7 years ago

I also have this issue on grunt contrib uglify 2.3.0

uglify: {
            common: {
              options: {
                    mangle: true,
                    compress: {
                      drop_console: true, // <- removes console.log 
                      hoist_funs: false // 
                    }
                },
                files: {
                    "<%= paths.compiled %>/common.min.js": [
                        '<%= paths.vendor %>/jquery-ui/jquery-ui.min.js',
                        '<%= paths.vendor %>/jquery.countdown/jquery.countdown.min.js',
                        '<%= paths.vendor %>/bootstrap/bootstrap.min.js',
                        '<%= paths.vendor %>/jquery-media/jquery.viewportchecker.min.js',
                        '<%= paths.static %>/jquery-media/js/jquery.countTo.js',
                        '<%= paths.vendor %>/vue/vue.min.js',
                        '<%= paths.vendor %>/vue/vue-resource.min.js',
                        '<%= paths.vendor %>/vue/vue-infinite-loading.js',
                        '<%= paths.static %>/js/components/ajax-utils.js',
                        '<%= paths.static %>/js/global.js',
                        '<%= paths.static %>/js/components/selecttextevent.js',
                        '<%= paths.static %>/js/components/smart_select.js',
                        '<%= paths.static %>/js/components/utils.js',
                        '<%= paths.static %>/js/components/words.js',
                        '<%= paths.static %>/js/components/auth.js',
                        '<%= paths.static %>/js/sections/landing.js',
                        '<%= paths.static %>/js/sections/socials.js',
                        '<%= paths.static %>/js/sections/actions.js',
                        '<%= paths.static %>/js/sections/publications.js',
                        '<%= paths.static %>/js/sections/projects.js',
                        '<%= paths.static %>/js/sections/people.js',
                    ],
                },
            },
}