简体   繁体   English

Gulp不会将结果写入文件

[英]Gulp doesn't write result to file

I have a gulpfile.js that looks like this: 我有一个看起来像这样的gulpfile.js

var gulp = require('gulp'),
concat = require('gulp-concat'),
less = require('gulp-less'),
minifyCSS = require('gulp-minify-css'),
uglify = require('gulp-uglify'),
autoprefixer = require('gulp-autoprefixer');

gulp.task('less', function () {
    gulp.src(['less/*.less'])
        .pipe(less())
        .pipe(concat('everything.css'))
        .pipe(autoprefixer())
        .pipe(minifyCSS())
        .pipe(gulp.dest('asset/'));
});

gulp.task('js', function () {
    gulp.src(['javascript/*.js'])
        .pipe(concat('everything.js'))
        .pipe(uglify())
        .pipe(gulp.dest('asset/'));
});

gulp.task('watch', function() {
    gulp.watch('javascript/*.js', ['js']);
    gulp.watch('less/*.less', ['less']);
});

As I was developing, the less task stopped working out of the blue. 在我开发过程中,较少的任务停止了突然的工作。 The console doesn't throw any errors, everything looks just like it should but the everything.css file does not get updated. 控制台不会引发任何错误,一切看起来都应该看起来一样,但是everything.css文件不会得到更新。 I even removed the file and it doesn't get created again. 我什至删除了该文件,并且不再创建它。

I'm compeltely clueless to what's going on, even rebooted my computer as a sanity check but it didn't help. 我对正在发生的事情一无所知,甚至重新启动了计算机以进行健全性检查,但这无济于事。

EDIT: So apparently it's the less pipe. 编辑:所以显然这是less管道。 But why did it start to fail suddenly? 但是为什么它突然开始失败了?

Try updating your less files a bit, to simplify. 为简化起见,请尝试少更新一些文件。 This is a common design pattern, and it works very well for me: 这是一种常见的设计模式,对我来说效果很好:

/*main.less*/
@import "somefile.less"
@import "some/deep/nested/file.less"

In your other less files, those will be where you keep your actuall less code. 在其他较少的文件中,这些文件将是您保留实际less代码的位置。

Then in your gulpfile.js you will want to modify a bit: 然后,在您的gulpfile.js您将需要进行一些修改:

...
gulp.task('less', function () {
    gulp.src(['less/main.less']) //only pull in your main.less file
        .pipe(less())
        .pipe(autoprefixer())
        .pipe(minifyCSS())
        .pipe(gulp.dest('asset/'));
});
...

gulp.task('watch', function() {
    gulp.watch('javascript/*.js', ['js']);
    gulp.watch('less/*.less', ['less']); //this remains the same - you want to watch for all changes
});

Note: gulp.watch will not find new files - you will need to restart when you have new files, or use something like gulp-watch . 注意: gulp.watch不会找到新文件-拥有新文件或使用gulp-watch类的文件时,您需要重新启动。

This will solve all kinds of headaches for you. 这将为您解决各种头痛问题。 Hope it helps! 希望能帮助到你!

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

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