Grunt concat + uglify with sourcemaps

前端 未结 2 1644
逝去的感伤
逝去的感伤 2020-12-13 02:52

I use concat to merge JS files into one file and uglify to minimize the JavaScript. How can I create a sourcemaps file that uses the source JS files?

My current gru

相关标签:
2条回答
  • 2020-12-13 03:11

    Per the grunt-contrib-uglify docs, you can enable sourcemap generation as part of the uglify process.

    Your uglify config would look something like:

    uglify: {
            dist: {
                files: {
                    '<%= config.dist %>/js/main.min.js': ['<%= concat.dist.dest %>']
                },
                options: {
                    sourceMap: true
            }
        },
    
    0 讨论(0)
  • 2020-12-13 03:13

    You need to enable source maps on both the concat and uglify tasks, and you must specify the sourceMapIn option for the uglify task.

    Here's a sample grunt config:

    concat : {
      options : {
        sourceMap :true
      },
      dist : {
        src  : ['www/js/**/*.js'],
        dest : '.tmp/main.js'
      }
    },
    uglify : {
      options : {
        sourceMap : true,
        sourceMapIncludeSources : true,
        sourceMapIn : '.tmp/main.js.map'
      },
      dist : {
        src  : '<%= concat.dist.dest %>',
        dest : 'www/main.min.js'
      }
    }
    
    0 讨论(0)
提交回复
热议问题