【发布时间】:2020-04-11 22:10:16
【问题描述】:
我正在尝试部署我的 Web 应用程序的前端,但是当我部署到我的托管平台(当前为 AWS Amplify/S3)时 - website 上没有显示任何内容
我使用create-react-app 创建了应用程序,因此项目结构遵循他们的标准(public、src 文件夹等)。
当我在本地运行应用程序时,它工作正常。
从控制台错误来看,并查看 webpack 生成的 index.html 页面,它似乎没有替换应该在构建时替换为公共目录的 %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
【问题讨论】:
标签: reactjs webpack deployment web-deployment aws-amplify