React应用程序生产构建静态文件夹路径更改
我正在使用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
// .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;
}
回答如下:您可以在包json“ homepage”:“。中检查和更新吗?或改为“ /”并重新生成。不需要覆盖。
React应用程序生产构建静态文件夹路径更改
我正在使用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
// .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;
}
回答如下:您可以在包json“ homepage”:“。中检查和更新吗?或改为“ /”并重新生成。不需要覆盖。