【问题标题】:Gulp is adding \r\n instead of just \nGulp 正在添加 \r\n 而不仅仅是 \n
【发布时间】:2015-08-17 21:29:22
【问题描述】:

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

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

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

提前致谢!

【问题讨论】:

    标签: javascript jquery macos gulp minify


    【解决方案1】:

    我已经使用gulp-frep解决了这个问题

    在您的gulpfile.js 中制作这样的模式:

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

    然后只需运行 gulp-frep 在编写源映射后 sourcemaps.write('.')

    另外更好地过滤流文件以仅对源映射应用替换(例如使用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 文件也是如此

    【讨论】:

      猜你喜欢
      • 2014-12-17
      • 2010-12-20
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 2019-12-15
      • 1970-01-01
      • 1970-01-01
      • 2022-07-29
      相关资源
      最近更新 更多