【问题标题】:How to serve components outside of the build directory with gulp-serve如何使用 gulp-serve 为构建目录之外的组件提供服务
【发布时间】:2017-09-15 12:57:00
【问题描述】:

使用gulp-serve插件,我在根bin/dev/服务我的应用程序,我的文件夹结构如下:

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

index.html 中对bower_components/ 的注入引用如下所示:

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

运行gulp serve 时,导航到应用程序时不包含组件,例如找不到"../../bower_components/angular/angular.js"

这是我的 gulp 任务:

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

如何为我的应用程序提供服务并在构建目录之外包含资产?

【问题讨论】:

    标签: javascript build gulp


    【解决方案1】:

    我选择改用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 是路径./ 的根。

    然后我可以简单地将我的脚本注入index.html 使用类似的东西:

    "bower_components/angular/angular.js"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-22
      • 1970-01-01
      • 2017-07-12
      • 1970-01-01
      • 1970-01-01
      • 2016-09-05
      相关资源
      最近更新 更多