Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I put React in production mode? #696

Closed
Drillan767 opened this issue Aug 24, 2017 · 6 comments
Closed

How do I put React in production mode? #696

Drillan767 opened this issue Aug 24, 2017 · 6 comments

Comments

@Drillan767
Copy link

I read the documentation quite a lot of time but i still can't figure this out, I finished building and compiling my application using Webpacker and React, but I just noticed that the React extension in my Chrome browser says that I'm using the development mode of React. How do I set it to production?

I read a lot of StackOverflow posts saying that you need to edit the package.json file and add some elements in it, but it always refer to a webpack.config.js , and i'm not really sure about where I cand find this file -- if it exists anywhere else than in node_module.

My most sincere apologies if this is an already asked question or if the answer is obvious, but I can't anything about this topic anywhere.

@gauravtiwari
Copy link
Member

@Drillan767 You would need to set NODE_ENV=production or RAILS_ENV=production

NODE_ENV=production bundle exec rails assets:precompile

@Drillan767
Copy link
Author

Thank you, it was way easier than I thought!

@mayordwells
Copy link

mayordwells commented Jun 18, 2018

@gauravtiwari @Drillan767 if you are hosting on a platform like Heroku, where do you set

NODE_ENV=production or RAILS_ENV=production

NODE_ENV=production bundle exec rails assets:precompile

??
I'm getting the same warning in a Rails + Webpacker + React project that I have in production and hosting on Heroku.
Please help. Thanks.

screen shot 2018-06-18 at 9 19 48 pm

@gauravtiwari
Copy link
Member

gauravtiwari commented Jun 18, 2018

You could set NODE_ENV=production in Heroku env variables:

heroku config:set NODE_ENV=production

and redeploy

@mayordwells
Copy link

@gauravtiwari Wow! that's quite straightforward. Thanks for the quick reply.

@Drillan767
Copy link
Author

If it might help, I recently learned that running "rails webpacker:compile" without providing any environment will set the ENV to "production" by default (and do the work)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants