我正在尝试使用 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);
});
});
如何使应用程序加载?
我是否必须在 HTML 页面中包含 bundle.js 才能使其工作?