gpt4 book ai didi

javascript - Gulp.js - 在变化时观察和编译 swig.js 模板文件

转载 作者:搜寻专家 更新时间:2023-10-31 22:56:13 24 4
gpt4 key购买 nike

我遇到了观看我的 Swig.js html 模板并在每次更改时编译它们的问题,为此我使用了 Gulp.js 任务运行器。这是我的 gulpfile.js:

var gulp = require('gulp');
var myth = require('gulp-myth');
var swig = require('gulp-swig');
var nodemon = require('gulp-nodemon');

gulp.task('styles', function () {
gulp.src('./myth/*.css')
.pipe(myth())
.pipe(gulp.dest('./client/css'));
});

gulp.task('templates', function () {
gulp.src('./views/*.html')
.pipe(swig({ load_json: true }))
.pipe(gulp.dest('./client'));
});

gulp.task('server', function () {
gulp.run('styles');
gulp.run('templates');

gulp.src('./server.js').pipe(nodemon());

gulp.watch('./myth/*.css', function () {
gulp.run('styles');
});

gulp.watch('./views/*.html', function () {
gulp.run('templates');
});
});

Myth 任务 styles 运行良好 - 在每次更改 myth/*.css 时我都在 client/css 中更新了文件/..

但是名为 templates 的任务只给出一次结果。当我更改 client/index.html 中的 views/index.html 文件时,它仍然存在相同。在我的控制台中,我看到 templates 任务已运行,但结果仍然相同。

MacBook-Pro-Dmitri:slick-grid dmitri$ gulp server
[gulp] Using file /Users/dmitri/github/slick-grid/gulpfile.js
[gulp] Working directory changed to /Users/dmitri/github/slick-grid
[gulp] Running 'server'...
[gulp] Running 'styles'...
[gulp] Finished 'styles' in 4.02 ms
[gulp] Running 'templates'...
[gulp] Finished 'templates' in 1.29 ms
[gulp] Running 'watch'...
[gulp] Finished 'watch' in 7.23 ms
[gulp] Finished 'server' in 16 ms
>> Strata web server version 0.20.1 running on node 0.10.21
>> Listening on 0.0.0.0:9000, CTRL+C to stop

// Here I changed my views/index.html, task is ran as you see (but dest file won't be updated):

[gulp] Running 'templates'...
[gulp] Finished 'templates' in 668 μs
127.0.0.1 - - [11/Jan/2014:15:43:20 +-200] "GET / HTTP/1.1" 200 511
127.0.0.1 - - [11/Jan/2014:15:43:20 +-200] "GET /css/reset.css HTTP/1.1" 200 1419
127.0.0.1 - - [11/Jan/2014:15:43:20 +-200] "GET /css/app.css HTTP/1.1" 200 865
127.0.0.1 - - [11/Jan/2014:15:43:20 +-200] "GET /fonts/likeastore-icon-font.ttf HTTP/1.1" 200 15052

也许我遗漏了一些缓存选项或类似选项?!

最佳答案

Gulp-Swig 已更新为允许禁用缓存选项 - 以及设置其他 swig 默认值,如下所示。

gulp.task('templates', function() {
gulp.src('./views/*.html')
.pipe(swig({
load_json: true,
defaults: {
cache: false,
locals: {
site_name: "My Blog"
}
}
}))
.pipe(gulp.dest('./client'));
});

关于javascript - Gulp.js - 在变化时观察和编译 swig.js 模板文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21063017/

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