【问题标题】:Remove Source Mapping with Gulp使用 Gulp 删除源映射
【发布时间】:2015-09-14 14:15:51
【问题描述】:

我正在使用 Gulp 和 Bower 将 JQuery 放入我的项目中。但是 jquery.min.cs 文件在预编译文件的末尾有一个 SourceMappingURL,我想删除它。

目前我的 Gulp 只是像这样将原始文件复制到目的地:

gulp.task('jquery', function () {
    gulp.src(paths.jquerySrc)
        .pipe(gulp.dest(paths.jqueryDest));
});

我找到了很多添加源映射的方法,但没有一个可以删除。我不想仅仅为此重新编译所有的 jquery。

【问题讨论】:

    标签: jquery gulp bower


    【解决方案1】:

    你可以试试这个:

    const paths = {
        jquerySrc: './path/to/src/jquery.css',
        jqueryDest: './path/to/dest/'
    };
    
    gulp.task('jquery', function () {
        gulp.src(paths.jquerySrc)
            .pipe(sourcemaps.init({loadMaps: true}))
            .pipe(sourcemaps.write('/dev/null', {addComment: false}))
            .pipe(gulp.dest(paths.jqueryDest));
    });
    

    您也可以尝试strip-source-map-loader 包。从来没有使用过,但理论上两者都应该可以工作,也许。

    【讨论】:

    • 效果很好!我试过这个,但我错过了'/dev/null'。
    • 在我的系统(osx)中,这会在源文件夹中创建一个名为“dev”的实际目录,并在其中创建另一个名为“null”的目录。
    • 令我惊讶的是,并非每个系统都发生这种情况。您的系统上的 Robert McKee 和 @max-bündchen 是否将“null”视为特殊的非目标,即使有引号?
    • @henry 不是。 /dev/null 是一种特殊的设备,它会丢弃写入它的所有内容。 DOS/Windows 有类似的设备NUL:\\.\NUL。不知道为什么当它是一个绝对目录名称(权限问题?)时它会在你的源代码树下创建一个文件夹,但我相当有信心 osx 也有/dev/null
    • 啊,这就是我没有测试的结果。我错过了最初的/ 并且不太了解我的nixes。我看到 OSX 确实有/dev/null。还没有测试,但我希望它可以工作
    【解决方案2】:

    gulp-purge-sourcemaps 包对我有用。 以下是您将对示例执行的操作:

    const purgeSourcemaps = require('gulp-purge-sourcemaps');
    
    gulp.task('jquery', function () {
        gulp.src(paths.jquerySrc)
            .pipe(sourcemaps.init({loadMaps: true}))
            .pipe(purgeSourcemaps())
            .pipe(gulp.dest(paths.jqueryDest));
    });
    

    【讨论】:

      【解决方案3】:

      在 Windows 上,这里的任何响应都不适合我。
      我对这个问题有不同的方法,但有一个权衡:你会从输出中丢失所有的 cmets。

      const stripComments = require('gulp-strip-comments')
      
      gulp.task('jquery', function () {
          gulp.src(paths.jquerySrc)
              .pipe(stripComments({trim: true}))
              .pipe(gulp.dest(paths.jqueryDest));
      });
      

      欲了解更多信息:gulp-strip-comments

      【讨论】:

        猜你喜欢
        • 2019-10-02
        • 2016-03-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-13
        • 2017-02-06
        • 2015-01-09
        • 1970-01-01
        相关资源
        最近更新 更多