我是 ReactJS 的真正初学者。我需要你帮助为 localhost:8080 设置 webpack-dev-server。
我正在关注这个设置它,但在教程中它的工作中我还无法获得成功。它将根路径设置为../node_module/.bin并在其中列出了我的文件。应该将 root 设置为“react-for-everyone”。
See Image https://i.stack.imgur.com/XbscG.png检查 webpack-dev-server 的文件层次结构、浏览器和命令。
包.json:
{
"name": "react-for-everyone",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies":{
"babel-core": "^6.1.*",
"babel-loader": "^6.2.*",
"babel-preset-es2015": "^6.16.*",
"babel-preset-react": "^6.16.*",
"webpack": "^1.13.*",
"webpack-dev-server": "^1.16.*"
},
"dependencies":{
"react": "^15.3.*",
"react-dom": "^15.3.*"
}
}
webpack-config.js:
module.exports ={
// entry:'./src/App.js',
entry: [
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
'./src/App.js'
],
output: {
path: path.resolve(__dirname, "react-for-everyone"),
filename: 'app.js',
publicPath: 'http://localhost:8080'
},
devServer: {
contentBase: "./react-for-everyone",
},
module:{
loader:[{
test: "/\.jsx?$/",
exclude: /node_modules/,
loader: "babel",
query: {
preset: ['es2015', 'react']
}
}]
}
};
索引.html:
<!DOCTYPE html>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<div id="app">This is an App.</div>
<script src="app.js"></script>
</body>
</html>
请检查并让我知道我做错的问题。