codesandbox-client icon indicating copy to clipboard operation
codesandbox-client copied to clipboard

Being able to run sandboxes in production mode

Open drcmda opened this issue 6 years ago • 11 comments

🌈 Feature

Quoting Dan Abramov on Twitter:

at least, for React, just switching NODE_ENV is enough. Maybe offer an option?

I wasn't aware that csb isn't running in prod, had no idea that dev mode in general has this kind of impact: https://twitter.com/dan_abramov/status/1136526025393754112

The original demo is here: https://codesandbox.io/s/peaceful-johnson-txtws it goes so slow that it's barely moving at all.

I am mostly using csb for presentational matters, when you want to demonstrate a library in the best light or some functionality. It would be nice to know the underlying framework's doing its best. 🙂

drcmda avatar Jun 06 '19 07:06 drcmda

Good point! The tricky thing about enabling "production mode" is that we don't do the uglifying/tree-shaking, so we need to communicate clearly that we're only changing the environment variable there and that it doesn't reflect real prod apps.

There are two ways I can think of making this work:

  1. We add it as an option to sandbox.config.json
  2. We fix the sandbox if NODE_ENV=production in .env file. We do support .env files right now, but I added a hardcoded optimization to only include the dev bundle in the case of React. That's why this doesn't work: https://codesandbox.io/s/jovial-jepsen-efe8f. I can remove the optimization in case of a changed env variable, it would also be good to document this better.

CompuIves avatar Jun 06 '19 10:06 CompuIves

Both seem like a good way, thanks for considering this Ives!

drcmda avatar Jun 06 '19 10:06 drcmda

This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.

github-actions[bot] avatar Sep 04 '20 13:09 github-actions[bot]

still much needed :-)

drcmda avatar Sep 04 '20 13:09 drcmda

True, removing the label

SaraVieira avatar Sep 04 '20 13:09 SaraVieira

This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed.

github-actions[bot] avatar Dec 04 '20 00:12 github-actions[bot]

This issue has been automatically closed because there wasn't any activity after the previous notice or the stale label wasn't removed.

github-actions[bot] avatar Dec 19 '20 00:12 github-actions[bot]

This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed.

github-actions[bot] avatar Mar 25 '21 00:03 github-actions[bot]

Bump

diegohaz avatar Mar 25 '21 00:03 diegohaz

We used to be able to do this by deploying to Netlify or Vercel. It seems that these options were removed.

oliviertassinari avatar May 01 '24 21:05 oliviertassinari

Yep. We haven't reimplemented Netlify/Vercel yet with the new APIs. In the meantime, it is possible to do this with devboxes. You can do this either by:

  1. Running the dev server in prod mode
  2. Deploying from the terminal
  3. Connecting the project to a GitHub repository and set up an automated flow from there

For adding a production mode to sandboxes, it should now be easier because AFAIK the hardcoded dev mode is not there anymore. The resulting preview will not be "real" production mode (with tree shaking etc), but it will run the production version of React.

Actually, looking at the code, it looks like we already do support NODE_ENV from .env (code here). So it should not be much extra to support production mode! I can experiment with this.

CompuIves avatar May 02 '24 15:05 CompuIves