javascript - 使用 gulp 时显示 javascript 错误

标签 javascript node.js gulp gulp-concat gulp-uglify

大家好,我正在使用 gulp uglify 和 concat 来缩小 js 代码。

但是,我希望有一种方法来检测原始 dev js 代码中的任何编码错误,以便我可以检查原始代码,而不仅仅是在缩小后通知。

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

下面是我的 gulp 代码。

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'}));   
});

最佳答案

这就是源映射的用途。

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 等现代浏览器,您将看到原始代码。

关于javascript - 使用 gulp 时显示 javascript 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26671442/

相关文章:

javascript - Bootstrap Modal 改变链接

node.js - 如果在测试过程中无法重现错误,如何测试 catch 子句?

node.js - npm - 错误 : The specified procedure could not be found

javascript - 使用 Critical 和 Gulp 为每个 *.HTML 文件生成 Critical CSS

javascript - 总结许多连续 if(x typeof != ='unedfined' ) 查询的最佳方法?

javascript - IBM Mobile First Platform (6.3) - Windows Phone 8 环境和 Angularjs

mysql - 如何在node.js中的mysql包中设置IF条件

node.js - 如何使用 Gulp 在流中替换?

javascript - Handlebars - 在客户端使用 Handlebars

javascript - 如何根据 JavaScript 中基于字符串的表达式返回 true 或 false?