[英]React application production build static folder path changes
我正在使用 react-app-rewired 在 package.json 中構建我的 react 應用程序。
"scripts": {
"format": "prettier --write",
"start": "PORT=3001 react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test"
},
但是當它構建時,它給了我在 index.html 中注入的以下樣式表,如下所示,這可能是默認值。
<link href="/static/css/main.dc83752a.css" rel="stylesheet">
我希望將其更改為以下內容。
<link href="static/css/main.dc83752a.css" rel="stylesheet">
我也嘗試使用根文件夾中的 config-overrides.js。 但它沒有用。 誰能幫我解決問題? 我的 config-overrides.js 如下。
const ExtractTextPlugin = require("extract-text-webpack-plugin");
// later after upgrade create-react-app to support
// webpack4 it can be removed becuase it now supports
// async css styles through mini-css-extract-plugin
// that future version of create-react-app also supports
// https://github.com/facebook/create-react-app/blob/next/packages/react-scripts/config/webpack.config.prod.js#L423
module.exports = function override(config, env) {
config.plugins[4] = new ExtractTextPlugin({
filename: 'static/css/[name].[contenthash:8].css',
allChunks: true,
});
return config;
}
您能否在 package json “主頁”:“。”中檢查和更新或“/”並再次重建。 不需要覆蓋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.