Webpack 4和react-router-dom无法正确构建

时间:2019-09-20 03:56:25

标签: javascript reactjs webpack react-router

我碰到了react-router与webpack4不兼容的问题。 webpack 4无法构建组件,我认为我的webpack配置有问题,但是我不知道如何修复设置。

这些是webpack-dev-server上的网站和构建后的截图。 enter image description here

enter image description here

module.exports = {
  devServer: {
    contentBase: './dist',
    open: true,
    port: Port,
    compress: true,
    publicPath: '/',
    historyApiFallback: true,
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
        },
      },
      {
        test: /\.html$/,
        use: [
          {
            loader: 'html-loader',
          },
        ],
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader'],
      },
      {
        test: /\.s[ac]ss/i,
        use: ['style-loader', 'css-loader', 'sass-loader'],
      },
      {
        test: /\.(png|svg|jpg|gif)$/,
        use: ['file-loader'],
      },
    ],
  },
  plugins: [
    new HtmlWebPackPlugin({
      template: './index.html',
      filename: './index.html',
    }),
  ],
  resolve: {
    extensions: ['.js', '.jsx'],
  },
};

建立与webpack-dev-server相同的网站

0 个答案:

没有答案