2014-10-31 57 views
0

大家好我使用gulp uglify和concat来缩小js代码。使用gulp时显示javascript错误

但是,我想有一种方法来检测原始开发人员代码中的任何编码错误,以便我可以检查原始代码,不仅在缩小后通知。

我可以知道我该怎么做吗?

以下是我的代码。

gulp.task('frontend.js', function() { 
    return gulp.src([paths.dev.js + 'jquery.js', paths.dev.js + 'bootstrap.js', paths.dev.js + 'basic.js']) 
    .pipe(jsconcat('script.js')) 
    .pipe(uglify()) 
    .pipe(gulp.dest(paths.assets.js)) // output: script.js 
    .pipe(notify({message: 'frontend.js converted'})); 
}); 

回答

2

这就是源地图的用途。

var sourcemaps = require('gulp-sourcemaps'); 

gulp.task('frontend.js', function() { 
    return gulp.src([paths.dev.js + 'jquery.js', paths.dev.js + 'bootstrap.js', paths.dev.js + 'basic.js']) 
    .pipe(jsconcat('script.js')) 
    .pipe(sourcemaps.init()) 
    .pipe(uglify()) 
    .pipe(sourcemaps.write()) 
    .pipe(gulp.dest(paths.assets.js)) // output: script.js 
    .pipe(notify({message: 'frontend.js converted'})); 
}); 

它会附加源映射(即映射每个精缩线到原来的行)frontend.js

现在,如果您使用的是现代浏览器,例如Chrome或Firefox,则会看到原始代码。

0

你的意思是你想串联和涅槃的源文件之前,或者你想为能的方式被通知JavaScript错误将缩小文件上的运行时错误与包含违规代码的原始源文件进行匹配?

在后一种情况下,麦克回答是否完美,否则你应该在jsconcat之前使用jshint-stylish作为jshint记者拨打电话gulp-jshint