繁体   English   中英

sass构建后,gulpfile.js并未连接所有css

[英]gulpfile.js is not concatenating all css after sass build

这是我的gulpfile.js

"use strict";

var gulp = require('gulp');
var connect = require('gulp-connect'); //Runs a local dev server
var open = require('gulp-open'); //Open a URL in a web browser
var browserify = require('browserify'); // Bundles JS
var reactify = require('reactify');  // Transforms React JSX to JS
var source = require('vinyl-source-stream'); // Use conventional text streams with Gulp
var concat = require('gulp-concat'); //Concatenates files
var lint = require('gulp-eslint'); //Lint JS files, including JSX
var livereload = require('gulp-livereload');

var sass = require('gulp-sass');
var config = {
    port: 9005,
    devBaseUrl: 'http://localhost',
    paths: {
        html: './src/*.html',
        js: './src/**/*.js',
        scss: [
            'node_modules/font-awesome/scss/font-awesome.scss',
            './src/scss/default.scss'

        ],
        sassBuilds: './src/builds/css/',
        css: [
            'node_modules/bootstrap/dist/css/bootstrap.min.css',
            'node_modules/bootstrap/dist/css/bootstrap-theme.min.css',
            './src/builds/css/*.css'
        ],
        fonts:[
            'node_modules/font-awesome/fonts/**.*'
        ],
        dist: './dist',
        mainJs: './src/main.js'
    }
}
//Start my local development server
gulp.task('connect', function() {
    connect.server({
        root: ['dist'],
        port: config.port,
        base: config.devBaseUrl,
        livereload: true
    });
});

gulp.task('open', ['connect'], function() {
    gulp.src('dist/index.html')
        .pipe(open({ uri: config.devBaseUrl + ':' + config.port + '/', app: 'Chrome'}));
});

gulp.task('livereload', function (){
    gulp.src('./src/**/*')
        .pipe(connect.reload());
});

gulp.task('html', function() {
    gulp.src(config.paths.html)
        .pipe(gulp.dest(config.paths.dist))
        .pipe(connect.reload());
});

gulp.task('js', function() {
    browserify(config.paths.mainJs)
        .transform(reactify) //this would 'bundle' the JSX
        .bundle()
        .on('error', console.error.bind(console))
        .pipe(source('bundle.js'))
        .pipe(gulp.dest(config.paths.dist + '/scripts'))
        .pipe(connect.reload());
});

gulp.task('css', function() {
    gulp.src(config.paths.css)
        .pipe(concat('bundle.css'))
        .pipe(gulp.dest(config.paths.dist + '/css'));
});

gulp.task('lint', function() {
    return gulp.src(config.paths.js)
        .pipe(lint({config: 'eslint.config.json'}))
        .pipe(lint.format());
});

gulp.task('watch', function() {
    gulp.watch(config.paths.html, ['html', 'livereload']);
    gulp.watch(config.paths.scss, ['sass', 'livereload']);
    gulp.watch(config.paths.js, ['js', 'lint']);
});

gulp.task('sass', function () {
    return gulp.src(config.paths.scss)
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest(config.paths.sassBuilds));
});

gulp.task('icons', function() {
    return gulp.src(config.paths.fonts)
        .pipe(gulp.dest(config.paths.dist + '/fonts'));
});
gulp.task('default', ['html', 'sass',  'js',  'lint', 'css', 'icons', 'open', 'watch']);

sass任务首先运行以在builds/css/创建2个CSS文件

在该css任务运行之后,应从config.paths.css合并所有css文件,但实际上没有,仅watch任务, 几乎没有 (有时),有时(没有)。 我觉得这里有些意大利面。

如果您期望sass任务将始终在css任务启动之前完成,请不要执行。 gulp文档

注意:任务将并行运行(全部一次),因此请不要假定任务将按顺序启动/完成。

解决此问题的常用方法是通过以下步骤使css任务等待sass任务完成:

gulp.task('css', ['sass'], function() {

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM