webpack.config不起作用,只有我可以看到目录树

时间:2019-08-28 16:55:13

标签: react-router webpack-dev-server

我需要一些帮助,我有一个带有webpack的react app,它不起作用。在文章末尾,我会在设置应用程序时附上一张包含结果的图片

package.json

  "name": "app-weather",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "bulma": "^0.7.5",
    "dotenv": "^8.0.0",
    "node-sass": "^4.12.0",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-router-dom": "^5.0.1",
    "react-scripts": "3.0.1"
  },
  "scripts": {
    "start": "webpack-dev-server --open",
    "build": "webpack --mode production",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@babel/core": "^7.5.5",
    "@babel/preset-env": "^7.5.5",
    "@babel/preset-react": "^7.0.0",
    "babel-loader": "^8.0.6",
    "css-loader": "^3.2.0",
    "handlebars": "^4.1.2",
    "html-loader": "^0.5.5",
    "html-webpack-plugin": "^3.2.0",
    "sass-loader": "^7.3.1",
    "style-loader": "^1.0.0",
    "webpack": "^4.39.3",
    "webpack-cli": "^3.3.7",
    "webpack-dev-server": "^3.8.0"
  }
}

webpack.config.js

const path = require('path')

module.exports = {

    entry: path.resolve(__dirname, 'src/index.js'),
    watch: true,
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist'),
    },
    node: {
        fs: 'empty'
    },
    devServer: {
        open: true
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)?$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-react', '@babel/preset-env']
                    }
                }
            },
            {
                test: /\.s[ac]ss$/i,
                use: ['style-loader', 'css-loader', 'sass-loader']
            },
        ],
    },
}

我的树

enter image description here

尝试npm启动结果的结尾是下一张图片

enter image description here

0 个答案:

没有答案