首页 > 解决方案 > npm run build 后未找到清单和其他几个静态文件(字体)

问题描述

npm run build 后未找到清单和其他几个静态文件(字体)。

该应用程序由create-react-app.

在里面public/index.html <link rel="manifest" href="%PUBLIC_URL%/manifest.json">

文件出现在 build 文件夹中并成功部署。我可以使用 Azure Kudu 服务找到它们。favicon.ico 和其他静态元素运行良好。只有清单和两种字体存在问题。

对于本地运行: "app:start": "react-app-env --env-file=dev.env start" "start": "npm run app:start"

对于构建: "app:dev": "react-app-env --env-file=dev.env build" "build": "npm run semantic:build && npm run app:build" "semantic:build": "gulp build --gulpfile ./src/semantic/gulpfile.js"

获取https://public.url/manifest.json 404

清单:行:1,列:1,语法错误。

获取https://public.url/static/media/icons.af7ae505.woff2 net::ERR_ABORTED 404

获取https://public.url/static/media/icons.fee66e71.woff net::ERR_ABORTED 404

标签: reactjsfontsmanifestcreate-react-app

解决方案


已修复。将一段代码添加到public/web.config

<staticContent>
            <remove fileExtension=".json" />
            <mimeMap fileExtension=".json" mimeType="application/json" />
            <remove fileExtension=".woff" />
            <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
            <remove fileExtension=".woff2" />
            <mimeMap fileExtension=".woff2" mimeType="font/x-woff" />
</staticContent>  

推荐阅读