如何删除 create-react-app 的 package.json 主页中的最后一个 /

How to remove the last / in create-react-app's package.json homepage

我正在尝试 运行 在 Tridium Jace-8000 设备上做出反应。文件 urls 的文件是这样的:

https://localhost/ord/file:^static/js/90.5af7b6f6.chunk.js

我能够将以下内容放入 package.json 文件中:

"homepage": "./file:%5E"(替换 /file:^ 以避免特殊字符)

但是,它在 url 的末尾添加了一个斜杠,所以我最终在控制台中出现如下错误:

GET https://localhost/ord/file:%5E/static/css/90.f2a8a0e3.chunk.css
net::ERR_ABORTED 400 (Bad Request)

如你所见,在%5Estatic之间多了个/。

有什么方法可以强制构建过程跳过额外的 / 吗?

谢谢,

如果有人需要这个,我通过确保每个 JS 或 CSS 在构建时只有 1 个文件来修复它,使用以下而不是正常构建:

const rewire = require('rewire');
const defaults = rewire('react-scripts/scripts/build.js');
let config = defaults.__get__('config');

config.optimization.splitChunks = {
    cacheGroups: {
        default: false,
    },
};

config.optimization.runtimeChunk = false;

我启动这个构建脚本是因为我将我的 package.json 修改为 运行 这个文件而不是正常的构建。

我还必须确保禁用我在这个项目中的任何 LazyLoad,并将其替换为通常的 import

然后,构建完成后,我必须在 index.html 文件中进行如下更改:

来自: <link href="./static/css/main.0c6501c3.css" rel="stylesheet"> <script src="./static/js/main.5dfc694d.js"></script>

致: <link href="static/css/main.0c6501c3.css" rel="stylesheet"> <script src="static/js/main.5dfc694d.js"></script>

然后我进入我电脑的站点备份文件夹,将构建的文件放在站点的根目录下,使用 niagara vykon workbench 软件将其上传到 Tridium Jace。

此外,我不得不修改反应路由器以使用 MemoryHistory 而不是常规路由器,因为 Jace 中的更改 URL 是有问题的。

import { createMemoryHistory } from 'history'
  const memoryHistory = createMemoryHistory({
    initialEntries: [ '/' ],  // The initial URLs in the history stack
    initialIndex: 0,          // The starting index in the history stack
    keyLength: 6,             // The length of location.key
    // A function to use to confirm navigation with the user. Required
    // if you return string prompts from transition hooks (see below)
    getUserConfirmation: null
  });

const App = props => <Router history={memoryHistory}/>;

我做的一个额外步骤是在我站里的 nav.nav 文件中添加一个我称为 home.html 的重定向页面作为主页。这是脚本标签。这会在 jace 上全屏启动 React 应用程序,而不是在嵌入菜单中。

<script>

window.location.replace("../file/index.html")
</script>