Javascript 使用Gulp和Glue构建HaPi应用程序

Javascript 使用Gulp和Glue构建HaPi应用程序,javascript,node.js,gulp,babeljs,hapijs,Javascript,Node.js,Gulp,Babeljs,Hapijs,我正试图让我的吞咽,以建立我的Hapi应用程序使用胶水清单配置服务器 我还使用Babel将代码传输到dist目录 我的目录结构如下所示: src/index.js "use strict"; import fs from 'fs'; import Glue from 'glue'; import minimist from 'minimist'; const args = minimist(process.argv.slice(2)); // load configuration con

我正试图让我的吞咽,以建立我的Hapi应用程序使用胶水清单配置服务器

我还使用Babel将代码传输到dist目录

我的目录结构如下所示:

src/index.js

"use strict";

import fs from 'fs';
import Glue from 'glue';
import minimist from 'minimist';

const args = minimist(process.argv.slice(2));

// load configuration
const envConfigFile = args['env-config'] || 'config/local.json';
const envConfig = JSON.parse(fs.readFileSync(envConfigFile));
const manifest = envConfig.manifest;
manifest.server.app = envConfig;

// compose Hapi server from config file
Glue.compose(manifest, { relativeTo: process.cwd() }, (err, server) => {
  if (err) { return console.error(err); }
  server.start(() => {
    console.log('hapi days!');
  });
});
const gulp = require("gulp");
const connect = require('gulp-connect'); // Runs a local dev server
const babel = require("gulp-babel"); // Use Babel with gulp
const lint = require('gulp-eslint'); // Lint JS files

const config = {
    port: 9005,
    devBaseUrl: 'http:localhost',
    paths: {
        js: 'src/**/*.js',
        dist: 'dist/',
        mainJs: 'dist/index.js'
    }
};

// Start a local development server
gulp.task('connect', function() {
    connect.server({
        root: ['dist'],
        port: config.port,
        base: config.devBaseUrl,
        livereload: true
    });
});

gulp.task("babel", function() {
    return gulp.src(config.paths.js)
        .pipe(babel())
        .pipe(gulp.dest(config.paths.dist));
});

gulp.task("babel-watch", function() {
    gulp.watch(config.paths.js, ["babel"]);
});

gulp.task("lint", function () {
    return gulp.src(config.paths.js)
        .pipe(lint({config: 'eslint.config.json'}))
        .pipe(lint.format());
});

gulp.task('watch', function () {
    gulp.watch(config.paths.js, ['lint']);
});

gulp.task("default", ["babel", "babel-watch", "lint", "watch"]);
gulpfile.js

"use strict";

import fs from 'fs';
import Glue from 'glue';
import minimist from 'minimist';

const args = minimist(process.argv.slice(2));

// load configuration
const envConfigFile = args['env-config'] || 'config/local.json';
const envConfig = JSON.parse(fs.readFileSync(envConfigFile));
const manifest = envConfig.manifest;
manifest.server.app = envConfig;

// compose Hapi server from config file
Glue.compose(manifest, { relativeTo: process.cwd() }, (err, server) => {
  if (err) { return console.error(err); }
  server.start(() => {
    console.log('hapi days!');
  });
});
const gulp = require("gulp");
const connect = require('gulp-connect'); // Runs a local dev server
const babel = require("gulp-babel"); // Use Babel with gulp
const lint = require('gulp-eslint'); // Lint JS files

const config = {
    port: 9005,
    devBaseUrl: 'http:localhost',
    paths: {
        js: 'src/**/*.js',
        dist: 'dist/',
        mainJs: 'dist/index.js'
    }
};

// Start a local development server
gulp.task('connect', function() {
    connect.server({
        root: ['dist'],
        port: config.port,
        base: config.devBaseUrl,
        livereload: true
    });
});

gulp.task("babel", function() {
    return gulp.src(config.paths.js)
        .pipe(babel())
        .pipe(gulp.dest(config.paths.dist));
});

gulp.task("babel-watch", function() {
    gulp.watch(config.paths.js, ["babel"]);
});

gulp.task("lint", function () {
    return gulp.src(config.paths.js)
        .pipe(lint({config: 'eslint.config.json'}))
        .pipe(lint.format());
});

gulp.task('watch', function () {
    gulp.watch(config.paths.js, ['lint']);
});

gulp.task("default", ["babel", "babel-watch", "lint", "watch"]);
config/config.json

{
  "sql": {
    "client": "mysql",
    "connection": {
      "host": "localhost",
      "user": "root",
      "password": "",
      "database": "apptest"
    }
  },
  "manifest": {
    "server": {

    },
    "connections": [
      {
        "port": 8000,
        "labels": ["web"]
      },
      {
        "port": 8001,
        "labels": ["admin"]
      }
    ],
    "registrations": [
      {
        "plugin": {
          "register": "hapi-knex-builder",
          "options": {}
        }
      },
      {
        "plugin": {
          "register": "good",
          "options": {
            "reporters": {
              "console": [
                {
                  "module": "good-console"
                },
                "stdout"
              ]
            }
          }
        }
      }
    ]
  }
}
当我使用该节点运行我的应用程序时,它工作正常,但不会在浏览器上启动(假设原因是缺少路由)

我使用node运行我的代码,如下所示:

node dist/ --env-config config/config.json
输出:

process.cwd()=项目/节点/用户,但您的所有代码都驻留在
dist
中,对吗?我建议使用
\uu dirname
而不是process.cwd().process.cwd()=项目/节点/用户,但您的所有代码都驻留在
dist
中,对吗?我建议使用
\uu dirname
而不是process.cwd()。