开发者社区> 问答> 正文

使用gulp-sourcemaps的一个疑问

我的SourceMap内嵌到文件中了,如何在发布的时候去掉这些SourceMap内容呢?
screenshot

展开
收起
杨冬芳 2016-06-03 11:18:19 2953 0
1 条回答
写回答
取消 提交回答
  • IT从业

    我用的是这样的结构 (gulpfile.js):

    // Environment setup.
    var env = {
        production: false
    };
    
    // Environment task.
    gulp.task("set-production", function(){
        env.production = true;
    });
    
    // Css process.
    gulp.task("postcss", function(){
        var processors = [
            autoprefixer({
                browsers: ["Android 4.1", "iOS 7.1", "Chrome > 31", "ff > 31", "ie >= 10"]
            })];
    
        if(env.production){
            processors.push(csswring());
            return gulp.src(["./stylesheets/src/*.css", "!./stylesheets/src/fontello.css"])
                .pipe(postcss(processors))
                .pipe(gulp.dest("./stylesheets/dest"));
    
        }else{
    
            return gulp.src(["./stylesheets/src/*.css", "!./stylesheets/src/fontello.css"])
                .pipe(sourcemaps.init())
                .pipe(postcss(processors))
                .pipe(sourcemaps.write("."))
                .pipe(gulp.dest("./stylesheets/dest"))
                .pipe(filter("*.css"))
                .pipe(reload({stream: true}));
        }
    });
    
    gulp.task("dev", ["postcss"]);
    gulp.task("release", ["set-production", "clean", "postcss"]);
    

    同一个postcss的构建任务,会有两条路径,生产环境路径不包含sourcemap。

    2019-07-17 19:26:22
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载