我是使用node.js和gulp的新手,我有这个特定的问题。我已经在全局和本地安装了gulp以确保在项目中编辑了gulp文件,但由于某些原因它似乎没有加载。它显示"任务监视不在你的gulpfile"无论我在哪里打字" gulp watch"。以下是我编辑文件本身的方式,感谢您的帮助。
/**
* Gulp Configuration
*
* We are using [gulp](http://gulpjs.com/) as a build system.
*/
var gulp = require( "gulp" ),
sass = require( "gulp-sass" ),
autoprefixer = require( "gulp-autoprefixer" ),
connect = require( "gulp-connect" ),
gutil = require( "gulp-util" ),
es = require( 'event-stream' ),
del = require( "del" );
/**
* Clean Task
*/
gulp.task( "clean", function() {
return del( ["./.build/**"] );
} );
/**
* Stylesheets Task
*/
gulp.task( "stylesheets", function() {
return gulp
.src( "./stylesheets/**/*.scss" )
.pipe( sass().on( "error", sass.logError ) )
.pipe( autoprefixer( { browsers : ["last 2 versions"] } ) )
.pipe( gulp.dest( "./.build/stylesheets" ) )
.pipe( connect.reload() )
.on( "error", gutil.log );
} );
/**
* Assets Task
*/
gulp.task( "assets", function() {
return es.merge(
gulp.src( "./images/**/*" )
.pipe( gulp.dest( "./.build/images" ) ),
gulp.src( "./fonts/**/*" )
.pipe( gulp.dest( "./.build/fonts" ) )
);
} );
/**
* HTML
*/
gulp.task( "html", function() {
return gulp
.src( "./html/**/*" )
.pipe( gulp.dest( "./.build" ) );
} );
/**
* Development
*/
gulp.task( "development", function() {
/** Development Server */
connect.server( {
port : 8080,
root : "./.build/",
livereload : true
} );
/** Watch any changes */
gulp.watch( "./stylesheets/**/*.scss", ["stylesheets"] );
/** Watch any html changes */
gulp.watch( "./html/**/*.html", ["html"] );
} );
/**
* Build task alias
*/
gulp.task( "build", ['stylesheets', 'assets', 'html'] );
答案 0 :(得分:0)
您需要一个名为watch
的gulp任务,如下所示:
gulp.task('watch', function() {
gulp.watch( "./stylesheets/**/*.scss", ["stylesheets"] );
gulp.watch( "./html/**/*.html", ["html"] );
});
答案 1 :(得分:0)
添加gulp watch任务:
gulp.task('watch', function(){
/** Watch any changes */
gulp.watch( "./stylesheets/**/*.scss", ["stylesheets"] );
/** Watch any html changes */
gulp.watch( "./html/**/*.html", ["html"] );
});