Gulp sourcemaps模块没有创建文件,没有错误

时间:2018-06-03 14:51:46

标签: npm gulp gulp-sourcemaps

我正在开发一个gulp工作流程,并且刚刚将gulp-sourcemaps传送到我的管道。但是它没有像它应该创建一个sourmapfile。我自由地管理我对文件夹目标参数感到困惑。我希望sourcemap与我的css文件位于同一个文件夹中,除非有充分的理由不这样做。

的package.json

{
  "name": "gulp-intro",
  "version": "1.0.0",
  "description": "Simple Gulp introduction",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-autoprefixer": "^5.0.0",
    "gulp-rename": "^1.2.3",
    "gulp-sass": "^4.0.1",
    "gulp-sourcemaps": "^2.6.4"
  }
}

Gulpfile.js

/**
 * = Gulp specific dependencies
 */
const gulp          = require('gulp');
const rename        = require('gulp-rename');

/**
 * = CSS Style task
 */
const sass          = require('gulp-sass');
const autoprefixer  = require('gulp-autoprefixer');
const sourcemaps    = require('gulp-sourcemaps');


const styleSrc      = './src/scss/style.scss';
const styleDist     = './assets/css/';

gulp.task('style', () => {
    gulp.src(styleSrc)
        .pipe(sass({
            errorLogToConsole: true,
            outputStyle: 'compressed'
        }))
        .on('error', console.error.bind(console))
        .pipe(autoprefixer({
            browsers: ['last 2 versions'],
            cascade: false
        }))
        .pipe(rename({
            suffix: '.min'
        }))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest(styleDist));
});

1 个答案:

答案 0 :(得分:0)

这被证明是一个愚蠢的错误,但我忘了在使用sourcemaps.init()开始我的gulp任务时初始化gulp-sourcemaps。

示例:

gulp.task('style', () => {
    gulp.src(styleSrc)

        // Initialize sourcemaps  
   ===> .pipe(sourcemaps.init() <===

        .pipe(sass({
            errorLogToConsole: true,
            outputStyle: 'compressed'
        }))
        .on('error', console.error.bind(console))
        .pipe(autoprefixer({
            browsers: ['last 2 versions'],
            cascade: false
        }))
        .pipe(rename({
            suffix: '.min'
        }))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest(styleDist));
});