我尝试将webpack用于使用socket.io的节点服务器。
我有一个简单的服务器:
var server = require('http').createServer();
var io = require('socket.io').listen(server);
io.on('connection', function(client) {
console.log('new client');
client.on('hello', function(data) {
console.log('msg: ', data);
});
client.on('disconnect', function(){
console.log('client disconnect');
});
});
server.listen(3000);
Run Code Online (Sandbox Code Playgroud)
还有我的webpack.config.js
var config = {
target: "node",
entry: {
server: ["server.js"]
},
module: {
loaders: [
{
test: /\.(txt|json|osgjs|osgt|bin)$/,
loader: "file?name=[path][name].[ext]"
}
],
noParse: ["ws"]
}
externals: ["ws"],
output: {
path: __dirname,
filename: "[name].js"
}
}
module.exports = config;
Run Code Online (Sandbox Code Playgroud)
当我“编译”我没有错误,只是一个警告:
> NODE_ENV=development BUILD_TARGET=server webpack --display-error-details
Hash: a692e23215bcd6caa05a
Version: webpack 1.13.2
Time: …Run Code Online (Sandbox Code Playgroud)