gulp打包 - 1 基本语法
pipe:用管道输送
1.gulp.src(glops[, options])
输出(Emits)符合所提供的匹配模式(glob)或者匹配模式的数组(array of globs)的文件。 将返回一个 Vinyl files 的 stream 它可以被 piped 到别的插件中。
gulp.src('html/javascript/**/*.js')
.pipe(minify())
.pipe(gulp.dest('build'));// 写入 'build/somedir/somefile.js'
gulp.src('html/javascript/**/*.js', { base: 'client' })
.pipe(minify())
.pipe(gulp.dest('build'));// 写入 'build/javascript/somedir/somefile.js'
2.gulp.dest(path[, options])
能被 pipe 进来,并且将会写文件。并且重新输出(emits)所有数据,因此你可以将它 pipe 到多个文件夹。如果某文件夹不存在,将会自动创建它。
gulp.src('./html/templates/*.jade')
.pipe(jade())
.pipe(gulp.dest('./html/templates'))
.pipe(minify())
.pipe(gulp.dest('./html/minified_templates'));
3.gulp.task(name[, deps], fn)
定义一个使用 Orchestrator 实现的任务(task)。
4.gulp.watch(glob[, opts, cb])
监视文件,并且可以在文件发生改动时候做一些事情。它总会返回一个 EventEmitter 来发射(emit) change 事件。
//每次变动需要执行的 callback
gulp.watch('js/**/*.js', function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});

浙公网安备 33010602011771号