我正在AngulaJS中做我的第一步。我尝试通过Bower和Gulpfile加载依赖项。
我安装了电线注射和保龄球。在我的Gulpfile.js中,我定义了接下来的任务:
'use strict';
var gulp = require('gulp');
var inject = require('gulp-inject');
var wiredep = require('wiredep').stream;
gulp.task('inject', function() {
var sources = gulp.src(['./app/scripts/**/*.js','./app/stylesheets/**/*.css']);
return gulp.src('index.html', {cwd: './app'}).pipe(inject(sources, {
read: false,
ignorePath: '/app'
})).pipe(gulp.dest('./app'));
});
gulp.task('wiredep', function () {
gulp.src('./app/index.html').pipe(wiredep({
directory: './app/lib'
})).pipe(gulp.dest('./app'));
});
gulp.task('watch', function() {
gulp.watch(['./app/stylesheets/**/*.css'], ['css', 'inject']);
gulp.watch(['./app/scripts/**/*.js', './Gulpfile.js'], ['jshint', 'inject']);
gulp.watch(['./bower.json'], ['wiredep']);
});
gulp.task('default', ['watch', 'inject', 'wiredep']);当我执行gulp命令时,app/样式表中允许的css是正确的,但app/lib中不允许包含JS文件。控制台输出是:
[21:37:17] Using gulpfile /var/www/angular/fullcity-dashboard/Gulpfile.js
[21:37:17] Starting 'watch'...
[21:37:17] Finished 'watch' after 15 ms
[21:37:17] Starting 'inject'...
[21:37:17] Starting 'wiredep'...
[21:37:17] Finished 'wiredep' after 3.2 ms
[21:37:17] gulp-inject 1 files into index.html.
[21:37:17] Finished 'inject' after 65 ms
[21:37:17] Starting 'default'...
[21:37:17] Finished 'default' after 15 μs我已经在我的index.html中定义了下一行:
<!-- bower:js -->
<!-- endbower -->
<!-- inject:js -->
<!-- endinject -->有什么想法吗?
更新1
我的文件.bowerrc位于项目根目录中,其内容如下:
{
"directory": "app/lib"
}我的bower.json:
{
"name": "sarasa",
"version": "0.0.1",
"description": "Sarasa",
"dependencies": {
"angular": "~1.4.0"
}
}我通过bower安装了角包,这个角包位于app/lib/转角下。
发布于 2015-06-12 01:29:25
我想说的是,您的任务正在按顺序执行,因为您没有返回任何流,也没有在其中执行回调(请参阅此处的注释~ https://github.com/gulpjs/gulp/blob/master/docs/API.md#deps)。
这可能意味着您的wiredep任务没有要处理的./app/index.html。我把这两个函数都移到一个任务中去,如
gulp.task('injectables', function() {
var sources = gulp.src(['./app/scripts/**/*.js','./app/stylesheets/**/*.css'], {read: false});
return gulp.src('index.html', {cwd: './app'})
.pipe(wiredep())
.pipe(inject(sources, {
ignorePath: '/app'
}))
.pipe(gulp.dest('./app'));
});https://stackoverflow.com/questions/30793636
复制相似问题