我正在尝试使用create-react-app更改开发中的bundle.js的src。
默认情况下,路径为:/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
<body>
<div id="root"></div>
</script><script type="text/javascript" src="myApp/static/js/bundle.js"></script></body>
我在package.json中尝试过主页,但它只适用于npm run build。它也不是代理设置,而不是.env中的HOSt
这甚至可以用create-react-app吗?我检查了文档,但没有找到任何解决方案。
你将不得不'npm run eject'并修改webpack文件来改变输出。
不太晚,但如果这有助于其他人,这就是你实现它的方式。弹出后,查看config文件夹,文件: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文件并添加:
PUBLIC_URL=/xxx