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

fix: always bundle SvelteKit, always externalize CommonJS dependencies during development #9203

Merged
merged 5 commits into from
Feb 26, 2023

Conversation

Rich-Harris
Copy link
Member

Simplifies noExternal, and reinstates the external config that #9172 incorrectly removes

@Rich-Harris Rich-Harris changed the title Rm external 2 fix: always bundle SvelteKit, always externalize CommonJS dependencies during development Feb 24, 2023
packages/kit/src/exports/vite/index.js Show resolved Hide resolved
packages/kit/src/exports/vite/index.js Show resolved Hide resolved
@@ -252,14 +252,13 @@ function kit({ svelte_config }) {
'$app',
'$env'
]
},
ssr: {
// These packages must be bundled by Kit so that we can resolve using the proper aliases and conditions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's true that we always need to bundle @sveltejs/kit. I expect it'd have negative performance implications. We really only need to do it if using Vitest to force it to go through the standard Vite pipeline instead of the vite-node pipeline so that resolveId is called

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'm back to being confused. Remind me why we need to ensure resolveId is called? @sveltejs/kit doesn't import any aliased modules. Is it about ensuring that we don't end up with two copies of HttpError (breaking instanceof checks) or something else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need resolveId to be called to handle our virtual modules. @sveltejs/kit imports __sveltekit/paths and __sveltekit/environment internally

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't. @sveltejs/kit resolves to src/exports/index.js which imports esm-env and src/runtime/control.js, which doesn't import anything (but we do need to ensure that those modules are only imported once for the instanceof checks, which is why I raise it)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing it appears to do no harm — tested it with a project that links @sveltejs/kit and uses redirect, and everything is fine

@Rich-Harris Rich-Harris merged commit 942ad18 into rm-external Feb 26, 2023
@Rich-Harris Rich-Harris deleted the rm-external-2 branch February 26, 2023 02:06
Rich-Harris added a commit that referenced this pull request Feb 27, 2023
* fix: don't force externalize SvelteKit

* bundle when using vitest

* update changelog description

* remove accidental comma

* Update packages/kit/src/exports/vite/index.js

* fix: always bundle SvelteKit, always externalize CommonJS dependencies during development (#9203)

* simplify

* add comments etc

* no need to noExternal kit itself

* update comment

* reinstate old comment

* work around vitest

* Update packages/kit/src/exports/vite/index.js

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>

---------

Co-authored-by: Rich Harris <richard.a.harris@gmail.com>
Co-authored-by: Rich Harris <hello@rich-harris.dev>
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

Successfully merging this pull request may close these issues.

2 participants