Gulp不会生成index.html

时间:2017-01-07 19:35:29

标签: javascript gulp

我正在使用Gulp进行以下设置:

var gulp = require('gulp');
var sass = require('gulp-sass');
var inject = require('gulp-inject');
var wiredep = require('wiredep').stream;
var del = require('del');

gulp.task('clean', function(cb){
    del(['dist'], cb);
});

gulp.task('styles', function(){
    var injectAppFiles = gulp.src('src/styles/*.scss', {read: false});
    var injectGlobalFiles = gulp.src('src/global/*.scss', {read: false});

    function transformFilepath(filepath) {
        return '@import "' + filepath + '";';
    }

    var injectAppOptions = {
        transform: transformFilepath,
        starttag: '// inject:app',
        endtag: '// endinject',
        addRootSlash: false
    };

    var injectGlobalOptions = {
        transform: transformFilepath,
        starttag: '// inject:global',
        endtag: '// endinject',
        addRootSlash: false
    };

    return gulp.src('src/main.scss')
        .pipe(wiredep())
        .pipe(inject(injectGlobalFiles, injectGlobalOptions))
        .pipe(inject(injectAppFiles, injectAppOptions))
        .pipe(sass())
        .pipe(gulp.dest('dist/styles'));
});

gulp.task('default', ['clean', 'styles'], function(){
    var injectFiles = gulp.src(['dist/styles/main.css']);

    var injectOptions = {
        addRootSlash: false,
        ignorePath: ['src', 'dist']
    };

    return gulp.src('src/index.html')
        .pipe(inject(injectFiles, injectOptions))
        .pipe(gulp.dest('dist'));
});

我希望得到dist / styles / main.css和dist / index.htm,但第二个不生成。我能做什么?我使用的数据包:gulp,gulp-sass,gulp-inject,bootstrap-sass(bower),wiredep,del

1 个答案:

答案 0 :(得分:0)

最后,我解决了我的问题。我刚从干净的回调中删除了一个变量cb

gulp.task('clean', function(cb){
    del(['dist'], cb);
});

- >

gulp.task('clean', function(){
    del(['dist']);
});