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

问题描述 投票:0回答:1

我正在尝试在Tridium Jace-8000设备上运行React。 文件的文件网址如下:

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之间有多余的/。

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

谢谢,

create-react-app
1个回答
0
投票

如果有人需要,我通过使用以下方法而不是正常的构建来确保每个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工作台软件将其上传到Tridium Jace。

另外,我必须修改react路由器以使用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>
© www.soinside.com 2019 - 2024. All rights reserved.