webpack-dev-server为root localhost设置了错误的路径:8080

时间:2016-10-07 08:23:17

标签: reactjs webpack webpack-dev-server

我是ReactJS的真正初学者。我需要你帮助为localhost:8080设置webpack-dev-server。 我跟着这个YouTube Tutorial进行了设置,但是在本教程的工作中我无法取得成功。它将根路径设置为 ../ node_module / .bin 并在其中列出我的文件。它应该将root设置为"为每个人做出反应"。

请参阅Image以检查webpack-dev-server的文件层次结构,浏览器和命令。

的package.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']
            }
        }]
    }
};

的index.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>

请检查并告诉我我做错的问题。

2 个答案:

答案 0 :(得分:2)

"dev": "./node_modules/.bin/webpack-dev-server --content-base"中添加scripts in package.json,然后在react-for-everyone <{1}}文件夹中运行您的网络包<{1}}

<强>的package.json

npm run dev

答案 1 :(得分:0)

您正在../node_module/.bin文件夹中运行webpack-dev-server命令,因此webpack-dev-server将提供此文件夹。您必须小心使用此命令的位置,因为它知道它从哪个文件夹启动。

要解决您的问题,请转到G:\ wamp \ react-for-anyone并在此文件夹中运行./node_modules/.bin/webpack-dev-server

这应该允许webpack-dev-server找到你的index.html并在http://localhost:8080上提供它。