使用Gulp jade的yeoman网络应用程序生成器出现Gulp错误
Gulp error with yeoman webapp generator using gulp-jade
我很难将jade与yeoman的gulp-webapp生成器集成在一起。观察任务已经按预期运行,但一旦我尝试构建项目,我就会收到以下错误:
stream.js:94
throw er; // Unhandled stream error in pipe.
^
TypeError: path must be a string
我认为这是因为我将html任务更改为return gulp.src('.tmp/*.html')
(最初是'app/*.html'
,它运行时没有出现错误,但当然会忽略我的jade模板)。
我的gulpfile:
'use strict';
// generated on 2014-04-17 using generator-gulp-webapp 0.0.7
var gulp = require('gulp'),
jade = require('gulp-jade');
// load plugins
var $ = require('gulp-load-plugins')();
gulp.task('styles', function () {
return gulp.src('app/styles/main.sass')
.pipe($.rubySass({
style: 'expanded',
compass: true,
loadPath: 'app/bower_components'
}))
.pipe($.autoprefixer('> 5%', 'last 3 versions', 'ff >= 20', 'ie 9'))
.pipe(gulp.dest('.tmp/styles'))
.pipe($.size());
});
gulp.task('templates', function() {
var YOUR_LOCALS = {};
return gulp.src('app/*.jade')
.pipe(jade({
locals: YOUR_LOCALS,
pretty: true
}))
.pipe(gulp.dest('.tmp'))
.pipe($.size());
});
gulp.task('scripts', function () {
return gulp.src('app/scripts/**/*.js')
.pipe($.jshint())
.pipe($.jshint.reporter($.jshintStylish))
.pipe($.size());
});
gulp.task('html', ['templates', 'styles', 'scripts'], function () {
var jsFilter = $.filter('**/*.js');
var cssFilter = $.filter('**/*.css');
return gulp.src('.tmp/*.html')
.pipe($.useref.assets())
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore())
.pipe($.useref.restore())
.pipe($.useref())
.pipe(gulp.dest('dist'))
.pipe($.size());
});
gulp.task('images', function () {
return gulp.src('app/images/**/*')
.pipe($.cache($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('dist/images'))
.pipe($.size());
});
gulp.task('fonts', function () {
return $.bowerFiles()
.pipe($.filter('**/*.{eot,svg,ttf,woff}'))
.pipe($.flatten())
.pipe(gulp.dest('dist/styles/fonts'))
.pipe($.size());
});
gulp.task('clean', function () {
return gulp.src(['.tmp', 'dist'], { read: false }).pipe($.clean());
});
gulp.task('build', ['html', 'images', 'fonts']);
gulp.task('default', ['clean'], function () {
gulp.start('build');
});
gulp.task('connect', function () {
var connect = require('connect');
var app = connect()
.use(require('connect-livereload')({ port: 35729 }))
.use(connect.static('app'))
.use(connect.static('.tmp'))
.use(connect.directory('app'));
require('http').createServer(app)
.listen(9000)
.on('listening', function () {
console.log('Started connect web server on http://localhost:9000');
});
});
gulp.task('serve', ['connect', 'styles', 'templates'], function () {
require('opn')('http://localhost:9000');
});
// inject bower components
gulp.task('wiredep', function () {
var wiredep = require('wiredep').stream;
gulp.src('app/styles/*.sass')
.pipe(wiredep({
directory: 'app/bower_components'
}))
.pipe(gulp.dest('app/styles'));
gulp.src('app/*.html')
.pipe(wiredep({
directory: 'app/bower_components'
}))
.pipe(gulp.dest('app'));
});
gulp.task('watch', ['connect', 'serve'], function () {
var server = $.livereload();
// watch for changes
gulp.watch([
'app/*.html',
'app/**/*.jade',
'.tmp/styles/**/*.css',
'app/scripts/**/*.js',
'app/images/**/*'
]).on('change', function (file) {
server.changed(file.path);
});
gulp.watch('app/**/*.jade', ['templates']);
gulp.watch('app/styles/**/*.sass', ['styles']);
gulp.watch('app/scripts/**/*.js', ['scripts']);
gulp.watch('app/images/**/*', ['images']);
gulp.watch('bower.json', ['wiredep']);
});
有什么建议吗?
显然,这个错误来自gulp-useref对我的构建块有问题。将所有块更改为使用{app,.tmp}
作为其搜索路径修复了行为,例如:
// build:js({app,.tmp}) scripts/vendor/modernizr.js
script(src='bower_components/modernizr/modernizr.js')
// endbuild
我遇到了同样的问题。
要修复wiredep
任务,请将其添加到gulp.src('app/*.html')
块之后:
gulp.src('app/*.jade')
.pipe(wiredep({
directory: 'app/bower_components'
}))
.pipe(gulp.dest('app'));
这将更新// bower:js
。。。当您的bower.json
发生变化时,// endbower
会在.jade
文件中阻塞,由手表触发:
gulp.watch('bower.json', ['wiredep']);
在你的gulpfile的末尾。
例如。
当我在bower.json
中添加"jquery": "~1.11.0"
作为依赖项时(并保存)。
在我的/app/layout.jade
文件中,这是:
body
// bower:js
// endbower
被替换为:
body
// bower:js
script(src='bower_components/jquery/dist/jquery.js')
// endbower
如果要在不将({app,.tmp})
添加到所有块的情况下使用build:js
,请在html
任务中,将app
和.tmp
都添加到源中。
您的.js
和.css
位于app
目录中,因此当您将源更改为.tmp/*.html
而不是app/*.html
时,您的两个$.筛选器找不到任何文件。
要解决此问题,请使gulp.src()
成为包含两个路径的数组。
替换:
gulp.task('html', ['templates', 'styles', 'scripts'], function () {
var jsFilter = $.filter('**/*.js');
var cssFilter = $.filter('**/*.css');
return gulp.src('.tmp/*.html')
...
带有:
gulp.task('html', ['templates', 'styles', 'scripts'], function () {
var jsFilter = $.filter('**/*.js');
var cssFilter = $.filter('**/*.css');
return gulp.src(['app/*.html', '.tmp/*.html'])
...
相关文章:
- gulp Iconify任务抛出错误TypeError:Path必须是字符串.收到false
- 最小化js时出现Gulp错误
- Gulp-Jasmine 给出了 SystemJS 的错误
- gulp-jquery验证错误
- Gulp,未捕获语法错误:意外的标记<
- Gulp 4 TypeScript编译错误
- Gulp 4 迁移错误(您是否忘记发出异步完成信号?
- 错误:[$injector:模块rr] 与角度 JS [GULP CONTEXT]
- Gulp.js 在 LESS 文件中出现错误后,在观看时停止编译 LESS
- Gulp 在 gulp.src() 中的符号链接上给出错误
- browserSync + Gulp,得到错误 => TypeError: _.contains 不是一个函数
- 如何从 gulp-esdoc 内部触发错误
- Gulp - 使用 gulp-uglify 和 gulp-concat 的意外令牌错误
- gulp - 导致任务停止的错误
- Gulp错误:找不到模块浏览
- 在gulp错误时恢复项目
- Gulp错误- TypeError:不能调用方法'match'的定义
- 使用Gulp jade的yeoman网络应用程序生成器出现Gulp错误
- 有scss的node_module上的Gulp错误
- 如何在丢失的文件上获得gulp错误