-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 environment variable when running svelte-kit package
#3215
Comments
Interesting. Could you elaborate a bit on the usecases, especially the custom build tools and how you integrate them with sveltekit package? Some initial thoughts:
|
In a component library built with sveltekit, "production" tells tools I'm building the site (i.e documentation etc.) and probably using an adapter, as it does in a regular sveltekit project; "development" tells them I'm in developing (components + site); and "packaging" would tell tools that I'm exporting the components. Therefore, I see value in using a custom value (e.g As for what I currently use a packing ENV variable:
|
I think you'd be better off with a custom mode ala vite, see this #1258 process.env.NODE_ENV has other uses already, it shouldn't be used to tell other parts of a system which command has been called. That would limit your abilities to do things as building with NODE_ENV=development |
From the linked issue, it seems config consumers and tooling have an overarching need for a sveltekit-ordained way to know what command led to them being called. But there's also the non-exclusive ENVs as you've mentioned (e.g build/packaging in dev/prod) to think about. Maybe a In the meantime, I'll leave a snippet here for completess for what I'm generally doing. // svelte.config.js
if (process.env.NODE_ENV === undefined) {
console.warn("[svelte.config.js] 'NODE_ENV' is undefined. Did you mean to set it to 'packaging'?\n");
}
const PKG = process.env.NODE_ENV === "packaging";
const preprocess = [
PKG ? prebundle() : undefined,
otherPreprocessor(),
].filter(Boolean);
const config = {
kit: {
preprocess,
...
vite: {
plugins [ otherPlugin({ preprocess }) ],
},
},
}; #.env
NODE_ENV=packaging && npx svelte-kit package |
I think we probably want to set |
Describe the problem
When writing a preprocessor, I've found it desirable to do different things (e.g warning vs error, optimize vs deoptimize etc.) based on the mode (e.g prod, dev etc.) that is running. Svelte-kit sets
NODE_ENV
to "development" and "production" for thedev
andbuild
modes respectively. It would be helpful if Svelte-kit does the same forsvelte-kit package
to allow different tools to behave accordingly.Describe the proposed solution
Before starting packaging simply set the process
NODE_ENV
to "packaging".Alternatives considered
Require that consumers of your preprocessor/build-tool MUST set the env variable to get correct behavior during packaging:
This is less convenient especially given that Svelte-kit "knows" that it's running in packaging mode.
Importance
nice to have
Additional Information
NODE_ENV
is currentlyundefined
during packaging.The text was updated successfully, but these errors were encountered: