使用gulp在Ubuntu 14.04上运行Angular JS应用程序。我的文件夹结构如下:
|-- app <--- main application folder
|-- bower_components
|-- bower.json
|-- env <--public folder; copy the main `/app` code while runtime
|-- gulpfile.js
|-- node_modules
`-- package.json
以下是任务。查看完整的gulpfile.js。
我已经在/app/index.html中添加了以下内容。
<!-- bower:js -->
<!-- endinject -->
inject
: inject all bower_components JS into env/index.htmlgulp.task('inject', function () { var target = gulp.src('./app/index.html'); var sources = gulp.src('./app/**/*.js'); return target .pipe($.inject(gulp.src(mainBowerFiles(), {read: false}),{ name: 'bower', relative:true})) .pipe(gulp.dest(src)) });
现在,问题出现了。
如果我在上面的任务中写入dest,即.pipe(gulp.dest('./env'))
,那么在/app和/env文件夹中都不会添加任何内容到index.html中。
并且
如果我写src,即.pipe(gulp.dest('./app'))
,那么所有的bower_components js文件都会被添加到index.html中(我认为这是由于copy
任务在inject
之后运行所导致的)。
<!-- bower:js -->
<script src="../bower_components/jquery/dist/jquery.js"></script>
<script src="../bower_components/angular/angular.js"></script>
<script src="../bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="../bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="../bower_components/angular-messages/angular-messages.js"></script>
<script src="../bower_components/ngstorage/ngStorage.js"></script>
<script src="../bower_components/angular-resource/angular-resource.js"></script>
<!-- endinject -->
copy
: which first complete browserify task and than copy all /app .html and .css to /env This seems confusing !!gulp.task('copy', ['browserify'], function() { gulp.src(['app/**/*.html','./app/**/*.css']) .pipe(gulp.dest(dest)) .pipe(browserSync.stream()); });
Now when we run
gulp
; Firefox opens up but the files inside<!-- bower:js -->
are added in page but browser can not find sources of these files. Kindly guide me
我需要使用wiredep或useref gulp模块吗?还是我漏掉了什么?