坚持使用React设置Webpack

时间:2018-03-02 21:42:47

标签: reactjs webpack webpack-dev-server

我曾尝试查看文档并在线搜索,但我很难用我的React项目配置webpack。我正在尝试使用webpack-dev-server。当我执行yarn start命令时,这就是我在浏览器中看到的内容。

Image of what I see in the browser

我不知道从哪里开始。这就是我的webpack.config.js的样子。



const path = require("path");

module.exports = {
    entry: './src/components/app.js',

    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'bundle.js'
    },

    devServer: {
        contentBase: "./dist"
    },

    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: 'babel-loader'
            }
        ]
    }
};




这是我的package.json



{
  "name": "react-portfolio",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-router-dom": "^4.2.2",
    "react-scripts": "1.1.1",
    "source-map-explorer": "^1.5.0"
  },
  "scripts": {
    "analyze": "source-map-explorer build/static/js/main.*",
    "start": "webpack-dev-server --open",
    "build": "webpack",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.3",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "webpack": "^4.0.1",
    "webpack-cli": "^2.0.9",
    "webpack-dev-server": "^3.1.0"
  }
}




非常感谢任何指导。

0 个答案:

没有答案