I am using grunt-contrib-uglify plugin to compress my javascript source files for production.
The problem occurs when I try to debug a function in chrome's dev-tools (or firefox's).
I set mangle:true (default value) in uglify task config in Gruntfile.js and uglifyjs mangles(shortens and renames) the variable names in the produced code.
These variables are not getting properly mapped to their original local variable names. So debugging is very painful.
Any ideas to fix this ?
Below is my Gruntfile.js
/* global module */
module.exports = function (grunt) {
grunt.initConfig({
copy: {
production: {
files: [
{
expand: true,
cwd: "./development/js/",
src: "./*",
dest: "./production/js/debug/"
}
]
}
},
uglify: {
production: {
options: {
sourceMap: true
/* mangle: false */
},
files: {
"./production/js/one.min.js": ["./development/js/one.js"],
"./production/js/two.min.js": ["./development/js/two.js"]
//"./production/js/app.js": ["./development/js/one.js" , "./development/js/two.js" ]
}
}
}
});
// [STEP] Load required GRUNT plugins
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
// [STEP] Register tasks
grunt.registerTask("default", ["copy:production", "uglify:production"]);
};
My directory structure is basically,
Project ROOT dir
--F-- package.json
--F-- Gruntfile.json
--D-- node_modules
--*---- * (module files folders)
--D-- development
--D---- js
--F------ one.js
--F------ two.js
--D-- production
--D---- js (generated from grunt)
--*------ * (generated files)
--D------ debug (generated from grunt)
--*-------- * (generated files)
--F---- index.html