【问题标题】:React application production build static folder path changesReact 应用程序生产构建静态文件夹路径更改
【发布时间】:2019-10-11 15:44:40
【问题描述】:

我正在使用 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;
}

【问题讨论】:

    标签: node.js reactjs webpack build


    【解决方案1】:

    你能检查和更新包 json "homepage": "."或“/”并再次重建。 不需要覆盖。

    【讨论】:

    • 好的,谢谢。有效。我用过这个。 “主页”:“。”
    猜你喜欢
    • 2021-06-13
    • 1970-01-01
    • 2019-02-17
    • 2018-05-20
    • 1970-01-01
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多