Browsersync开发完后 怎么配置node环境

yang_j_j
  • 838
// gulpfile.js
var fs          = require('fs');
var yaml        = require('js-yaml');
var gulp        = require('gulp');
var browserSync = require('browser-sync');

try {
    var options = yaml.safeLoad(fs.readFileSync('./config.yaml', 'utf-8'));
} catch (error) {
    throw new Error(error);
}

var taskDependencies = (function() {
    gulp.task('server', function() {
       options.browserSync.server.middleware.push(proxyMiddleware);
        browserSync(options.browserSync);
    });

    return ['server'];
}());

gulp.task('default', taskDependencies, function() {
    // Default Task Denifition
});


# config.yaml
---
browserSync: &browserSync
  files:
    - "public/**"
    - "source/**"
  watchOptions:
    debounceDelay: 3000
  server:
    baseDir: "public"
    routes:
      "/public": "./public/"
      "/build.js": "./build.js"
      "/config.js": "./config.js"
      "/jspm_packages": "./jspm_packages/"
      "/source": "./source/"
    # middleware: []
  startPath: "/"
  host: "127.0.0.1"
  port: 3000

现在开发完之后 node 怎么使用config.yaml 中的配置 部署项目呢?

回复
阅读 2.8k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏