create-react-app:在开发中更改bundle.js的src [英] create-react-app: Change src of bundle.js in development
问题描述
我正在尝试使用create-react-app更改开发中bundle.js的源代码。
I'm trying to change the src of bundle.js in development with create-react-app.
默认情况下,路径为:/ static / js / bundle.js
By default the path is: /static/js/bundle.js
<body>
<div id="root"></div>
</script><script type="text/javascript" src="/static/js/bundle.js"></script></body>
在我们的生产中,我们使用Apache作为我们API的代理,以测试SSO和其他功能。因此,我必须在路径中添加一些字符串,如下所示:myApp / static / js / bundle.js
In our production we use Apache as proxy to our API, to test SSO and other functionalities. So I have to add some string to the path, to be like this: myApp/static/js/bundle.js
<body>
<div id="root"></div>
</script><script type="text/javascript" src="myApp/static/js/bundle.js"></script></body>
我尝试了打包中的首页。 json,但仅适用于npm run build。
这也不是代理设置,不是.env中的HOSt
I tried homepage in package.json, but it only works in npm run build. It also isn't proxy settings, not HOSt in .env
使用create-react-app甚至可能吗?我检查了文档,但没有找到任何解决方案。
Is this even possible with create-react-app? I checked documentation but didn't find any solution.
推荐答案
来不及了,但是如果这对其他人有所帮助,这就是您的方法。弹出后,查看config文件夹中的文件:webpack.config.dev.js:
Little late but if this helps others, this is how you achieve it. After eject, take a look in the config folder, the file: webpack.config.dev.js:
const publicPath = '/';
// `publicUrl` is just like `publicPath`, but we will provide it to our app
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
const publicUrl = '';
您可以更改此值,或者第二个选择是创建.env文件并添加:
There you could change this values or, second option is to create a .env file and add:
PUBLIC_URL=/xxx
这篇关于create-react-app:在开发中更改bundle.js的src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!