kit icon indicating copy to clipboard operation
kit copied to clipboard

Ability to exclude files from compilation

Open NatoBoram opened this issue 2 years ago • 4 comments

Describe the problem

There are times when we need to exclude files from compilation. Here's some examples:

  • An app might not have some routes in the PWA build, like /admin, but it might have them in the SSR build
  • Some files can be problematic during compilations, like +page.server.ts

At the moment, these files have to be manually removed before the build then put back afterwards. It's cumbersome.

Describe the proposed solution

In svelte.config.js, define a function that acts as a filter to source code files so we can ignore some files.

Alternatives considered

Right now, if you want to ignore some files, you have to straight up delete them.

find src/routes -name '+*.server.*' -delete
pnpm build
http-server ./build
git checkout -- 'src/routes/+*.server.*'

Importance

would make my life easier

Additional Information

  • Fixes https://github.com/sveltejs/kit/issues/10332
  • https://github.com/sveltejs/kit/issues/6031#issuecomment-1593328625

NatoBoram avatar Jul 07 '23 15:07 NatoBoram

A more general solution would probably be some sort of plugin system where people can influence routes, and that could be done through that.

dummdidumm avatar Jul 07 '23 15:07 dummdidumm

I would like to bring this up again, and broaden the scope a bit; I want to exclude *.stories.svelte and *.spec.ts from the build artifacts, but there really doesn't seem to be a good way to do this.

Radiergummi avatar Apr 02 '25 06:04 Radiergummi

This is possible since a while via the typescript option: https://svelte.dev/docs/kit/configuration#typescript

Edit: misread this, sorry for the noise

dummdidumm avatar Apr 02 '25 08:04 dummdidumm

This is possible since a while via the typescript option: https://svelte.dev/docs/kit/configuration#typescript

Edit: misread this, sorry for the noise

I wish you could be a bit more specific. If I have a routes/dev folder, how do I exclude it? What file do I change and how?

dsfaccini avatar May 30 '25 19:05 dsfaccini

I have the same problem with *.page.ts, To hold Page Object Models for testing. Better for these to be co-located. @Radiergummi

Co-location of files reduces cognitive load.

I am confused on how to actually exclude pattern of files too. @dsfaccini

arkmech avatar Oct 19 '25 20:10 arkmech