简体   繁体   English

图像未显示在 AWS 放大中

[英]Images not showing up in AWS amplify

I build a simple app using React, React-Router and Webpack, and after deploying it AWS amplify, it fails to load up images.我使用 React、React-Router 和 Webpack 构建了一个简单的应用程序,在部署 AWS amplify 后,它无法加载图像。

Fonts load correctly in amplify.字体在放大中正确加载。 No errors show up in the console.控制台中没有显示任何错误。

Locally, everything works perfectly.在本地,一切正常。

Directories目录

my-app/
├─ build/
├─ node_modules/
├─ src/
│  ├─ assets/
│  │  ├─ some_img.png
│  ├─ index.css
│  ├─ index.js
├─ .gitignore
├─ package.json
├─ webpack.config.js

Current webpack conf:当前的 webpack 配置:

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const webpack = require('webpack');
const dotenv = require('dotenv').config({
    path: path.join(__dirname, '.env')
});
const MiniCssExtractPlugin = require('mini-css-extract-plugin');


module.exports = {
    entry: path.join(__dirname, "src", "index.js"),
    output: {
        path: path.join(__dirname, "build"),
        filename: "index.bundle.js",
        publicPath: '/',
    },
    mode: process.env.NODE_ENV || "development",
    resolve: {
        alias: {
            '../../theme.config$': path.join(
                __dirname,
                '/src/theme/theme.config',
            ),
        },
        modules: [path.resolve(__dirname, "src"), "node_modules"],
    },
    devServer: {
        contentBase: path.join(__dirname, "src"),
        historyApiFallback: true,
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/i,
                exclude: /node_modules/,
                use: ["babel-loader"]
            },
            {
                test: /\.(css)$/i,
                use: ["style-loader", "css-loader"],
            },
            {
                test: /\.s[ac]ss$/i,
                use: ["style-loader", "css-loader", "sass-loader"]
            },
            {
                test: /\.(jpg|jpeg|png|gif|woff|woff2|eot|ttf|svg|gif|mp3)$/i,
                use: ["file-loader"]
            },
            {
                test: /\.less$/,
                use: [
                    {
                        loader: MiniCssExtractPlugin.loader,
                    },
                    'css-loader',
                    'less-loader',
                ],
            },
            {
                test: /\.csv$/,
                loader: 'csv-loader',
                options: {
                  dynamicTyping: true,
                  header: true,
                  skipEmptyLines: true
                }
              }
        ],
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: path.join(__dirname, "src", "index.html"),
        }),
        new webpack.DefinePlugin({
            "process.env": JSON.stringify(dotenv.parsed)
        }),
        new MiniCssExtractPlugin({
            filename: 'styles/[name].[contenthash].css',
        }),
    ],
    devtool: "source-map",
    target: 'node',
}; 

Rewrites and redirects : I guess the problem is here, I looked in the docs, couldn't find any help.. 重写和重定向:我想问题出在这里,我查看了文档,找不到任何帮助..

[
    {
        "source": "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|woff2|ttf|map|json)$)([^.]+$)/>",
        "target": "/index.html",
        "status": "200",
        "condition": null
    }
]

If you need more info please ask.如果您需要更多信息,请询问。

Any ideas of what could be going on?关于可能发生什么的任何想法?

My webpack conf was wrong.我的 webpack conf 是错误的。 Note how the dev server points to src instead of build/dist:请注意开发服务器如何指向 src 而不是 build/dist:

    contentBase: path.join(__dirname, "src"),

Once I changed that I had the same problem in Local.一旦我改变了,我在本地遇到了同样的问题。 to solve it I added the CopyWebpackPlugin , which solved the issues both locally and online.为了解决它,我添加了CopyWebpackPlugin ,它解决了本地和在线问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM