为什么 %PUBLIC_URL% 在捆绑的 Webpack index.html 中没有被替换?

Why does %PUBLIC_URL% not get replaced in Webpack bundled index.html?

我正在尝试部署我的 Web 应用程序的前端,但是当我部署到我的托管平台(目前是 AWS Amplify/S3)时 - website[=21 上没有显示任何内容=]

我使用 create-react-app 创建了应用程序,因此项目结构遵循他们的标准(publicsrc 文件夹等)。

当我 运行 本地应用程序时,它工作正常。

从控制台错误来看,查看由 webpack 生成的 index.html 页面,看起来它没有替换应该替换为 [=40= 的 %PUBLIC_URL% 字段] 构建目录。

有人可以解释一下如何解决这个问题吗?

我在下面包含了我的 webpack.config 文件,可以找到完整的 repo here

const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

const config = {
  entry: ['react-hot-loader/patch', './src/index.js'],
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: 'bundle.js',
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        use: 'babel-loader',
        exclude: /node_modules/,
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader'],
      },
      {
        test: /\.svg$/,
        use: 'file-loader',
      },
      {
        test: /\.png$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              mimetype: 'image/png',
            },
          },
        ],
      },
      {
        test: /\.(ttf|eot|woff|woff2)$/,
        use: 'file-loader',
      },
    ],
  },
  resolve: {
    extensions: ['.js', '.jsx'],
    alias: {
      'react-dom': '@hot-loader/react-dom',
    },
  },
  devServer: {
    contentBase: './build',
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: path.resolve('./public/index.html'),
    }),
  ],
}

module.exports = config

事实证明这是我尝试将自定义 Webpack 配置添加到 create-react-app 项目时出现的问题。

我现在已经删除了 Webpack 配置,而是使用在使用 create-react-app 构建过程时创建的 dist 文件。