我有一个使用grunt,browserify和uglify的SPA ASP.NET项目。当我尝试在Chrome调试器中查看JavaScript时,它会显示缩小的JavaScript并且似乎忽略了地图文件。在IE11和Firefox中,调试器正确显示未分析的JavaScript。我确认在Chrome选项中选中了“启用JavaScript源地图”。
在Chrome中,缩小文件的最后一行是:
//# sourceMappingURL=bundledApp.min.js.map
这是我的完整gruntfile:
module.exports = function (grunt) {
grunt.initConfig({
clean: ['dist'],
browserify: {
build: {
files: {
"dist/bundledApp.js": [
'./Scripts/jquery-2.1.4.js',
'./Scripts/underscore.js',
'./Scripts/backbone.js',
'./App/App.js',
'./App/**/*.js',
'!./App/**/*-spec.js'
]
},
options: {
alias: {
'jquery': './Scripts/jquery-2.1.4.js',
'underscore': './Scripts/underscore.js',
'backbone': './Scripts/backbone.js'
},
transform: ['node-underscorify']
}
},
test: {
files: {
"dist/bundledApp.js": [
'./Scripts/jquery-2.1.4.js',
'./Scripts/underscore.js',
'./Scripts/backbone.js',
'./App/App.js',
'./App/**/*.js'
]
},
options: {
alias: {
'jquery': './Scripts/jquery-2.1.4.js',
'underscore': './Scripts/underscore.js',
'backbone': './Scripts/backbone.js'
},
transform: ['node-underscorify']
}
}
},
less: {
debug: {
options: {
compress: true,
optimization: 2
},
files: {
"dist/bundledApp.css": [
'App/App.less',
'App/**/*.less'
]
}
}
},
jasmine: {
src: [
'dist/bundledApp.js'
],
options: {
specs: [
'./App/**/*-spec.js'
],
vendor: [
'./Scripts/jquery-2.1.4.js',
'./Scripts/underscore.js',
'./Scripts/backbone.js'
]
}
}, uglify: {
build: {
options: {
sourceMap: true,
sourceMapName: 'dist/bundledApp.min.js.map',
},
files: {
'dist/bundledApp.min.js': ['dist/bundledApp.js']
}
}
}
});
// Load Grunt plugins
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-contrib-uglify');
// Default task(s).
grunt.registerTask('default', ['browserify:build', 'uglify', 'less']);
grunt.registerTask('test', ['browserify:test', 'jasmine']);
};