简体   繁体   English

如何使用 gulp-serve 在构建目录之外提供组件

[英]How to serve components outside of the build directory with gulp-serve

Using the gulp-serve plugin, I'm serving my application at root bin/dev/ , my folder structure is as follows:使用gulp-serve插件,我在根bin/dev/为我的应用程序提供服务,我的文件夹结构如下:

bower_components/
    angular/
bin/
  dev/
    scripts/
    content/
        css/
    index.html

The injected references to bower_components/ in index.html look like the following: index.htmlbower_components/的注入引用如下所示:

"../../bower_components/angular/angular.js"

When running gulp serve , the components aren't included when navigating to the application, eg "../../bower_components/angular/angular.js" could not be found.运行gulp serve时,导航到应用程序时不包含组件,例如"../../bower_components/angular/angular.js"

Here is my gulp task:这是我的吞咽任务:

gulp.task('serve', plugins.serve('bin/dev/'));

How can I serve my application and include assets outside of the build directory?如何为我的应用程序提供服务并在构建目录之外包含资产?

I opted to use the gulp-webserver plugin instead.我选择使用gulp-webserver插件代替。

I was able to serve files outside of the directory using the middleware option like so:我能够使用中间件选项在目录外提供文件,如下所示:

var webserver = require('gulp-webserver');
var serveStatic = require('serve-static');

gulp.task('serve', function () {
    gulp.src('./bin/dev/')
        .pipe(plugins.webserver({
            middleware: [
                serveStatic(__dirname)
            ]
        }));
});

Where __dirname is the root at path ./ .其中__dirname是路径./的根。

I could then simply inject my scripts into index.html using something like:然后我可以简单地使用以下内容将我的脚本注入index.html

"bower_components/angular/angular.js"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM