【发布时间】:2017-10-24 10:05:45
【问题描述】:
我正在尝试设置 node.js 服务器。目前,当我使用当前的 webpack.config.js 运行 npm start 时,一切都会加载。当我运行节点服务器时,index.js 丢失了。
webpack.config.js
var config = {
context: path.join(__dirname, 'src'),
entry: './js/main.js',
output: {
path: __dirname + '/src/',
filename: 'index.js',
},
devServer: {
inline: true,
port: 8080
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
}
]
}
}
module.exports = config;
这里是html,省略了不需要看的东西。
<html lang="en">
<head>
</head>
<body>
<div id="app"></div>
<script src="index.js"></script>
</body>
</html>
包.json
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"start": "webpack-dev-server --content-base src --hot",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"history": "^1.17.0",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-router": "^4.2.0",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.3"
},
"devDependencies": {
"express": "^4.16.2",
"http": "0.0.0",
"react-socket-io": "^0.2.4",
"socket.io": "^2.0.3",
"webpack": "^3.8.1"
}
}
我对 node.js 和 webpack 还很陌生,所以我不确定为什么在运行 npm start 时会输出 index.js 而不是在运行 node server 时。我可以上传 server.js,但它遵循一个非常基本的模板。
编辑:看来我已经成功了,我需要在不同的端口上运行 webpack 开发服务器以及 node.js 服务器。后续问题,是否可以将其更改为仅运行节点服务器并且仍然可以正常工作?
【问题讨论】:
-
使用开发服务器时,没有文件写入磁盘。这一切都是凭记忆提供的
标签: javascript html node.js reactjs webpack-dev-server