使用 gulp-serve插件,我在根 bin/dev/
下为我的应用程序提供服务,我的文件夹结构如下:
bower_components/
angular/
bin/
dev/
scripts/
content/
css/
index.html
index.html
中对 bower_components/
的注入(inject)引用如下所示:
"../../bower_components/angular/angular.js"
运行 gulp serve
时,导航到应用程序时不包括组件,例如"../../bower_components/angular/angular.js"
找不到。
这是我的 gulp 任务:
gulp.task('serve', plugins.serve('bin/dev/'));
我如何提供我的应用程序并包含构建目录之外的 Assets ?
最佳答案
我选择使用 gulp-webserver插件代替。
我能够像这样使用中间件选项在目录外提供文件:
var webserver = require('gulp-webserver');
var serveStatic = require('serve-static');
gulp.task('serve', function () {
gulp.src('./bin/dev/')
.pipe(plugins.webserver({
middleware: [
serveStatic(__dirname)
]
}));
});
其中 __dirname
是路径 ./
的根。
然后我可以简单地将我的脚本注入(inject)到 index.html
中,使用类似的东西:
“bower_components/angular/angular.js”
关于javascript - 如何使用 gulp-serve 为构建目录之外的组件提供服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46240150/