使用HapiJS和webpack构建应用程序

时间:2016-06-10 07:25:08

标签: javascript webpack hapijs webpack-dev-server webpack-hot-middleware

我正在尝试使用HapiJS和webpack构建一个应用程序。

然而,它并没有正确加载..

我的webpack配置是:

import webpack from 'webpack';
import path from 'path';

export default {
    debug: true,
    devtool: 'cheap-module-eval-source-map', // more info:https://webpack.github.io/docs/build-performance.html#sourcemaps and https://webpack.github.io/docs/configuration.html#devtool
    noInfo: true, // set to false to see a list of every file being bundled.
    entry: [
        'webpack-hot-middleware/client?reload=true',
        './src/index'
    ],
    target: 'web', // necessary per https://webpack.github.io/docs/testing.html#compile-and-test
    output: {
        path: `${__dirname}/dist`, // Note: Physical files are only output by the production build task `npm run build`.
        publicPath: 'http://localhost:3000/', // Use absolute paths to avoid the way that URLs are resolved by Chrome when they're parsed from a dynamically loaded CSS blob. Note: Only necessary in Dev.
        filename: 'bundle.js'
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin()
    ],
    module: {
        loaders: [
            {test: /\.js$/, include: path.join(__dirname, 'src'), loaders: ['babel']},
            {test: /\.json$/, loader: 'json'}
        ]
    },
    node: {
        fs: 'empty',
        net: 'empty',
        tls: 'empty',
        dns: 'empty'
    }
};

和src / index.js

'use strict';

import {Hapi} from 'hapi';
import {dateFormat} from 'dateformat';
import {Good} from 'good';
let format = "dd mmm HH:MM:ss";



// Basic Hapi.js connection stuff
let server = new Hapi.Server();
server.connection({
  host: 'localhost',
  port: 3000
});

server.route({
  method: 'GET',
  path: '/',
  handler: function (request, reply) {
    reply('Hello, world!');
  }
});

// Register the inert and vision Hapi plugins
// As of Hapi 9.x, these two plugins are no longer
// included in Hapi automatically
// https://github.com/hapijs/hapi/issues/2682
server.register({
  register: Good,
  options: {
    reporters: {
    console: [{
      module: 'good-squeeze',
      name: 'Squeeze',
        args: [{
        response: '*',
        log: '*'
        }]
      }, {
         module: 'good-console'
      }, 'stdout']
    }
  }
}, (err) => {

    if (err) {
        throw err; // something bad happened loading the plugin
    }
    server.start((err) => {
        if (err) {
            throw err;
        }
        console.log(dateFormat(new Date(), format) + ' - Server started at: ' + server.info.uri);
    });
});

如何加载应用程序?

我是否必须将bundle.js包含在HTML页面中才能使其正常工作?

0 个答案:

没有答案