我试图让我的吞咽"观看"任务运行。现在我每次都必须从命令行运行gulp(ps - 我在Windows 7上)。
我已经阅读了几篇类似的帖子,以及寻找语法错误。不幸的是,我的尝试都没有帮助。
var gulp = require('gulp');
var gutil = require('gulp-util');
var stylus = require('gulp-stylus');
var autoprefixer = require('autoprefixer-stylus');
var webpack = require('webpack');
var runSequence = require('run-sequence');
var del = require('del');
gulp.task('clean', function(cb) {
return del (['build/*'], cb);
});
gulp.task('copy', function() { });
gulp.task('images', function() {
gulp.src(['client/images/**/*.{jpg,png}'])
.pipe(gulp.dest('build/images'));
});
gulp.task('css', function() {
gulp.src(['client/css/**/*.styl'])
.pipe(stylus({
use:
[autoprefixer({browsers: ['last 2 versions', 'ie 10']})]
}))
.pipe(gulp.dest('build/css'));
});
gulp.task('js', function(cb) {
webpack(require('./webpack.config.js'), function(err, stats)
{
if(err) throw new gutil.PluginError('webpack.build', err);
gutil.log('[webpack:build]', stats.toString({
colors: true
}));
});
});
gulp.task('build', function(cb) {
runSequence('clean', ['copy', 'images', 'css', 'js'],
function() {
cb();
});
});
gulp.task('watch', ['build'], function() {
gulp.watch('client/**/*.styl', ['css']);
gulp.watch('client/**/*.jsx', ['js']);
});
gulp.task('default', ['watch']);
我还用"自动观看"更新了它。功能,但这也不起作用。
var gulp = require('gulp');
--> var autowatch = require('gulp-autowatch');
var gutil = require('gulp-util');
var stylus = require('gulp-stylus');
var autoprefixer = require('autoprefixer-stylus');
var webpack = require('webpack');
var runSequence = require('run-sequence');
var del = require('del');
gulp.task('clean', function(cb) {
return del (['build/*'], cb);
});
gulp.task('copy', function() { });
gulp.task('images', function() {
gulp.src(['client/images/**/*.{jpg,png}'])
.pipe(gulp.dest('build/images'));
});
gulp.task('css', function() {
gulp.src(['client/css/**/*.styl'])
.pipe(stylus({
use:
[autoprefixer({browsers: ['last 2 versions', 'ie 10']})]
}))
.pipe(gulp.dest('build/css'));
});
gulp.task('js', function(cb) {
webpack(require('./webpack.config.js'), function(err, stats)
{
if(err) throw new gutil.PluginError('webpack.build', err);
gutil.log('[webpack:build]', stats.toString({
colors: true
}));
});
});
gulp.task('build', function(cb) {
runSequence('clean', ['copy', 'images', 'css', 'js'],
function() {
cb();
});
});
-->var paths = {
--> images: 'client/**/*.{jpg,png}',
--> css: 'client/**/*.styl',
--> js: 'client/**/*.{js,jsx}',
-->};
-->
-->gulp.task('watch', ['build'], function() {
--> autowatch(gulp, paths);
-->});
gulp.task('default', ['watch']);
知道我做错了吗?
答案 0 :(得分:0)
我认为您需要指定正确的子文件夹。假设你分别使用client / css和client / js也许试试这个?
gulp.task('watch', ['build'], function() {
gulp.watch('client/css/**/*.styl', ['css']);
gulp.watch('client/js/**/*.jsx', ['js']);
});