用wiredep加载库
我正在AngulaJS上做第一步。 我尝试通过鲍尔和一个Gulpfile来加载依赖。
我已经安装了wiredep,gulp-inject和bower。 在我的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命令时,应用程序/样式表中允许的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"
}
}
我通过凉亭安装角度,角度包在app / lib / angular下。
我会说你的任务执行不按顺序执行,因为你没有返回任何流或者在其中一些回调中执行任何回调(见这里的注释〜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'));
});
链接地址: http://www.djcxy.com/p/20097.html
上一篇: Load libraries with wiredep
下一篇: Installer angular