webpack-dev-server 为 root localhost:8080 设置了错误的路径 [英] webpack-dev-server is setting wrong path for root localhost:8080

查看:20
本文介绍了webpack-dev-server 为 root localhost:8080 设置了错误的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 ReactJS 的真正初学者.我需要你帮助为 localhost:8080 设置 webpack-dev-server.我正在按照这个 YouTube 教程进行设置,但在教程中我还没有成功.它将根路径设置为 ../node_module/.bin 并在其中列出了我的文件.它应该将 root 设置为react-for-everyone".

I'm real beginner in ReactJS. I need you help to set up webpack-dev-server for localhost:8080. I'm following this YouTube Tutorial to set it up, but I can't get success yet while in the tutorial its working. it sets root path as ../node_module/.bin and listed me files in it. It should set root as "react-for-everyone".

请参阅 图像 以检查 webpack-dev- 的文件层次结构、浏览器和命令服务器.

See Image to check file hierarchy, browser and command for the webpack-dev-server.

package.json:

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:

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:

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>

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

Kindly check and let me know the issues where I'm doing wrong.

推荐答案

Add "dev": "./node_modules/.bin/webpack-dev-server --content-base" in scripts in package.json 并从 react-for-everyone 文件夹中运行你的 webpack 作为 npm run dev

Add "dev": "./node_modules/.bin/webpack-dev-server --content-base" in scripts in package.json and run your webpack form the react-for-everyone folder as npm run dev

Package.json

{
  "name": "react-for-everyone",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "dev": "./node_modules/.bin/webpack-dev-server --content-base",
    "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-dev-server 为 root localhost:8080 设置了错误的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆