grunt-contrib-uglify creates invalid source maps

It took me a little while to figure this one out. Uglify2 was uglifying and creating my source maps for sure, but when I looked in the console it would report the wrong line/file.

Until this issue is resolved, you must remove the banner option from your config. In a project of mine, codenamed Zoltar, this is my configuration, which is now working:

    uglify: {
      options: {
        report: 'min',
        sourceMap: 'public/javascripts/dist/<%= pkg.name %>-<%= pkg.version %>.map.js',
        sourceMapRoot: '/',
        sourceMapPrefix: 1,
        sourceMappingURL: '/javascripts/dist/<%= pkg.name %>-<%= pkg.version %>.map.js'
      },
      dist: {
        files: {
           // sources.json is a list of 3rd-party JS libs, in the correct order
           // generated dir is full of ngmin-generated files
          'public/javascripts/dist/<%= pkg.name %>-<%= pkg.version %>.min.js': [
            grunt.file.readJSON('sources.json').concat('public/javascripts/dist/generated/**/*.js')
          ]
        }
      }
    },

Again, you must remove the banner option from the config, until this issue is resolved.

One thought on “grunt-contrib-uglify creates invalid source maps

  1. Permalink  ⋅ Reply

    Paul Tibbetts

    October 9, 2013 at 6:19am

    Hey, found this because I’m having the same problem.
    Thanks for the write-up, I thought it was just me doing something wrong.

    There’s a couple of solutions on GitHub including one from the jQuery team but no proper solution just yet. Have you found a fix/alternative?

    - Paul

Leave a Reply

Your email will not be published. Name and Email fields are required.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>