How can I develop locally using a domain name instead of 'localhost:3000' in the url with create-react-app?

后端 未结 4 1530
野性不改
野性不改 2021-01-13 07:26

I have been developing a small app with create-react-app and a few other libraries i added. Given the planned architecture and some tests i\'d like to run with react-router,

4条回答
  •  温柔的废话
    2021-01-13 07:43

    As well as changing your /etc/hosts as advised above, if you want CRA to know about the new host name, the HOST env var should give you what you want.

    E.g. (this can go into your package.json under scripts/start)

    HOST=somedomain.com react-scripts start
    

    That should start your CRA-based dev server, listening at that domain name, and it should open/refresh a browser tab pointing there.

    Edit: docs on this and other env vars that CRA uses.

提交回复
热议问题