反应 - 反应脚本 publicPath [英] React - react-scripts publicPath

查看:30
本文介绍了反应 - 反应脚本 publicPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在开发环境的 react-scripts 中覆盖 publicPath.我使用 symfony 并且我在树枝中包含了反应应用程序,所以我不得不更改资产以从 http://localhost:3000/static/js/bundle.js - 这工作正常,但我对静态文件有问题,因为它们在浏览器中呈现为/static/media/logo.813ua.png"和我当前的网址是 http://localhost:8000

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

我所做的是在 webpack.config.dev.js 中运行纱线弹出和修改: var publicPath = 'http://localhost:3000/' 一切正常,但我不想弹出所以有没有可能在不弹出 react-scripts 的情况下做到这一点?

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 ?

推荐答案

使用 process.env.PORT (package.json)

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

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

这篇关于反应 - 反应脚本 publicPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆