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

Code is being sorted #271

Open
mbrammer opened this issue Nov 7, 2014 · 8 comments
Open

Code is being sorted #271

mbrammer opened this issue Nov 7, 2014 · 8 comments

Comments

@mbrammer
Copy link

mbrammer commented Nov 7, 2014

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
Copy link
Member

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
Copy link
Author

mbrammer commented Nov 7, 2014

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
Copy link
Member

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
Copy link
Author

mbrammer commented Nov 7, 2014

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
Copy link
Author

mbrammer commented Nov 7, 2014

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
Copy link
Author

@jmeas Can you reproduce this issue?

@argyleink
Copy link

+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
Copy link

pythdasch commented Apr 14, 2017

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',
                    ],
                },
            },
}

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

4 participants