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

Set production or development in conditions #3994

Open
benmccann opened this issue Nov 29, 2024 · 5 comments
Open

Set production or development in conditions #3994

benmccann opened this issue Nov 29, 2024 · 5 comments

Comments

@benmccann
Copy link

benmccann commented Nov 29, 2024

It would be nice if conditions always included development or production

E.g. vite build will automatically set the production condition while vite dev will automatically set the development condition. Rollup also sets the development and production conditions by default.

References:
https://vite.dev/config/shared-options#resolve-conditions
https://vite.dev/guide/env-and-mode#node-env-and-modes

Libraries like Svelte rely on this to be set. This works automatically in Vite and Rollup, but requires extra configuration in esbuild

If the user has not provided either production or development then set production by default or development if NODE_ENV === 'development'

@hyrious
Copy link

hyrious commented Nov 30, 2024

esbuild doesn't check NODE_ENV in its Go code. It does set process.env.NODE_ENV = "production" when all minification options are enabled. Maybe the same logic can be applied to the conditions field.

@benmccann
Copy link
Author

That seems reasonable as conditions and NODE_ENV should always be in sync as it would cause confusion to have their values differ

@evanw
Copy link
Owner

evanw commented Dec 20, 2024

Libraries like Svelte rely on this to be set. This works automatically in Vite and Rollup, but requires extra configuration in esbuild

Can you provide more information? Specifically: What breaks when you don't configure this in esbuild, and for what packages? Marking this issue as unactionable as it doesn't include any reproduction instructions. I'm also not seeing either the strings development or production in svelte/package.json (specifically here).

@hyrious
Copy link

hyrious commented Dec 20, 2024

@evanw It is in svelte's dependency esm-env's package.json.

I also have a trivial demo using svelte ssr which requires certain configurations to make the dev build work.

IMO, it is fine to NOT having this feature implemented because Node.js doesn't change runtime conditions by NODE_ENV too. On the other hand, for the specific package, esm-env, it also has reasonable fallbacks for no conditions case.

@benmccann
Copy link
Author

The main problem users will encounter is warnings that they have set neither the production nor development condition.

Users may also miss out on development warnings if they are running in development and do not set the corresponding condition:
https://github.com/search?q=repo%3Asveltejs%2Fsvelte+dev+esm-env+&type=code

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

No branches or pull requests

3 participants