Gulp是加上 而不是只加上

Gulp is adding instead of just

本文关键字:Gulp      更新时间:2023-09-26

我正在运行一个gulp任务,它正在缩小一对css和JS文件。它还同时创建源映射文件。

在源映射中,它将行尾转义为'r'n,我希望它将它们转义为'n

我的Mac和Windows都有这个问题。

提前感谢!

我通过使用gulp-frep

解决了这个问题

在你的gulpfile.js做一个这样的模式:

var pattern = [
   {
      pattern: /''r''n/g,
      replacement: '''n'
    }
];

写完源码图 sourcemaps.write('.')后直接运行gulp-frep

另外,最好将流文件过滤为,仅对源映射应用替换(例如使用gulp-if)。

下面是一个例子:

var pattern = [
   {
      pattern: /''r''n/g,
      replacement: '''n'
    }
];
gulp.task('projectJS', function() {
return gulp.src('pathToJS/*.js')
    .pipe(sourcemaps.init())
    .pipe(uglify())
    .pipe(concat('app.min.js'))
    .pipe(sourcemaps.write('.'))
    .pipe(gulpIf('*.map', frep(pattern)))
    .pipe(gulp.dest('./media/js/'));
});

css文件也是一样