gpt4 book ai didi

javascript - 当源文件夹中有多个jade文件时,gulp-jade仅构建一个HTML文件

转载 作者:行者123 更新时间:2023-12-03 07:01:49 25 4
gpt4 key购买 nike

我的 Gulpfile 存在问题,而且我似乎无法缩小问题范围。

我的 Gulpfile 设置如下:

var gulp = require('gulp'),
gutil = require('gulp-util'),
jade = require('gulp-jade'),
stylus = require('gulp-stylus'),
minify = require('gulp-minify'),
coffee = require('gulp-coffee'),
autoprefixer = require('gulp-autoprefixer'),
imagemin = require('gulp-imagemin'),
cache = require('gulp-cache'),
del = require('del'),
browserSync = require('browser-sync').create();

gulp.task('default', ['clean'], function() {
gulp.start('styles', 'markup', 'views', 'scripts', 'controllers', 'images', 'watch', 'serve');
});

gulp.task('serve', function() {
browserSync.init({
server: './public'
});
gulp.watch('public/stylesheets/*.css').on('change', browserSync.reload);
gulp.watch('public/js/*.js').on('change', browserSync.reload);
gulp.watch('public/js/*/*.js').on('change', browserSync.reload);
gulp.watch('public/*.html').on('change', browserSync.reload);
gulp.watch('public/*/*.html').on('change', browserSync.reload);
});

gulp.task('watch', function() {
gulp.watch('src/js/*.coffee', ['scripts']);
gulp.watch('src/js/*/*.coffee', ['controllers']);
gulp.watch('src/*/*.jade', ['views']);
gulp.watch('src/*.jade', ['markup']);
gulp.watch('src/stylesheets/*.styl', ['styles']);
gulp.watch('src/images/*', ['images']);
});

gulp.task('markup', function() {
gulp.src('src/*.jade')
.pipe(jade())
.pipe(minify())
.pipe(gulp.dest('public'))
.pipe(browserSync.stream());
});

gulp.task('views', function() {
var YOUR_LOCALS = {};
gulp.src('src/views/*.jade')
.pipe(jade({
locals: YOUR_LOCALS
}))
.pipe(minify())
.pipe(gulp.dest('public/views'))
.pipe(browserSync.stream());
});

gulp.task('styles', function() {
gulp.src('src/stylesheets/*.styl')
.pipe(stylus())
.pipe(autoprefixer())
.pipe(minify())
.pipe(gulp.dest('public/stylesheets'))
.pipe(browserSync.stream());
});

gulp.task('scripts', function() {
gulp.src('src/js/*.coffee')
.pipe(coffee())
.pipe(minify())
.pipe(gulp.dest('public/js'))
.pipe(browserSync.stream());

});

gulp.task('controllers', function() {
gulp.src('src/js/controllers/*.coffee')
.pipe(coffee())
.pipe(minify())
.pipe(gulp.dest('public/js/controllers'))
.pipe(browserSync.stream())
});

gulp.task('images', function() {
gulp.src('src/images/*')
.pipe(cache(imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('public/images'))
.pipe(browserSync.stream());
});

gulp.task('clean', function() {
return del(['public/js', 'public/stylesheets', 'index.html'])
});

还有一个 src/views 文件夹,如下所示:

src
└── views
├── login.jade
├── register.jade
└── success.jade

但是,当我运行 Gulpfile 时,它​​仅将第一个 jade 文件 (login.jade) 构建为 HTML,如下所示:

public
└── views
└── login.html

我怎样才能让它构建其余的文件?

如果我从源目录中删除login.jade 文件并运行gulp,它将构建行中的下一个文件,即register.jade。另外,我的 CoffeeScript 文件没有这个问题......

最佳答案

尝试改变:

gulp.watch('src/*/*.jade', ['views']);
gulp.watch('src/*.jade', ['markup']);

gulp.watch('src/**/*.jade, ['views']);
gulp.watch('src/**/*.jade', ['markup']);

关于javascript - 当源文件夹中有多个jade文件时,gulp-jade仅构建一个HTML文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37015946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com