React - react-scripts publicPath

时间秒杀一切 提交于 2021-02-20 19:02:10

问题


Is there possibility to override publicPath in react-scripts for dev env. I use symfony and I include react app inside twig so I had to change assets to serve from http://localhost:3000/static/js/bundle.js - this works fine but I have problem with static files because they are rendered in browser as '/static/media/logo.813ua.png' and my current url is http://localhost:8000

What I did is I run yarn eject and modify in webpack.config.dev.js: var publicPath = 'http://localhost:3000/' and everything is working fine but I don't want to eject so is there any possibility to do this without ejecting react-scripts ?


回答1:


Specify your port with with process.env.PORT (package.json)

"scripts": {
  "start": "PORT=1234 react-scripts start"
}


来源:https://stackoverflow.com/questions/43419053/react-react-scripts-publicpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!