1

我正在运行一个将 HAML 和 LESS 转换为 PHP 和 CSS 的简单脚本。我还使用 gulp.watch 来检查我所做的所有更改。

问题:gulp-less 和 gulp-haml 正确处理文件。但是当 gulp.watch 看到文件中的更改时,文件最终为空。gulp.watch 正在使用与成功创建 php 文件完全相同的任务。

var gulp = require('gulp');
var gutil= require('gulp-util');
var path = require('path');
var haml = require('gulp-haml');
var less = require('gulp-less');

// Images
gulp.task('less', function() {
    return gulp.src('wp-content/themes/luento/assets/less/*.less')
        .pipe(less({paths: [ path.join(__dirname, 'less', 'includes') ]}))
        .pipe(gulp.dest('wp-content/themes/luento/assets/css/'));
});

gulp.task('haml-def', function () {
    return gulp.src('wp-content/themes/luento/*.haml')
        .pipe(haml({ext: '.php'}))
        .pipe(gulp.dest('wp-content/themes/luento/'));
});

gulp.task('haml-templates', function () {
    return gulp.src('wp-content/themes/luento/templates/*.haml')
        .pipe(haml({ext: '.php'}))
        .pipe(gulp.dest('wp-content/themes/luento/templates/'));
});

gulp.task('haml-partials', function () {
    return gulp.src('wp-content/themes/luento/partials/*.haml')
        .pipe(haml({ext: '.php'}))
        .pipe(gulp.dest('wp-content/themes/luento/partials/'));
});

// Watch
gulp.task('watch', function() {
    // Watch .scss files
    gulp.watch('wp-content/themes/luento/templates/*.haml', ['haml-templates']);
    gulp.watch('wp-content/themes/luento/partials/*.haml', ['haml-partials']);
    gulp.watch('wp-content/themes/luento/*.haml', ['haml-def']);
    gulp.watch('wp-content/themes/luento/assets/less/*.less', ['less'])

});

gulp.task('default', ['less', 'haml-def', 'haml-templates','haml-partials','watch']);
4

0 回答 0