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

Config to exclude files from routing #2930

Closed
tony19 opened this issue Nov 26, 2021 · 6 comments
Closed

Config to exclude files from routing #2930

tony19 opened this issue Nov 26, 2021 · 6 comments
Labels
feature / enhancement New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc.

Comments

@tony19
Copy link
Contributor

tony19 commented Nov 26, 2021

Describe the problem

The following directory layout creates an endpoint for post.spec.js and post.md, and the only way to opt out is to make them private modules with an underscore/dot prefix:

src
└── routes
    └── posts
        ├── post.md  👈 converted to endpoint!
        ├── post.spec.js  👈 converted to endpoint!
        └── post.svelte

Some developers might require the exact layout/naming shown, where:

  1. The files are colocated
  2. The files have the same basename

Describe the proposed solution

Add a configuration option that excludes files.

For example, a kit.excludes config could accept an array of String, RegExp, or Function.

  • String - The basename of the file/directory is compared against the string, and it's excluded if matches.
  • RegExp - The basename of the file/directory is tested against the regular expression, and it's excluded if matches.
  • ({ filepath, basename }) => boolean - The file/directory is excluded if the function returns true.

The default would be [^_.] to match the current behavior. This also would enable users to override the current behavior, allowing for underscore/dot-prefixed files to be included in routing.

Alternatives considered

  • Use underscore/dot prefix to make the files private modules - Defeats requirement 1
  • Store the files outside of src/routes - Defeats requirement 2

Importance

nice to have

Additional Information

No response

@bluwy bluwy added p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. feature / enhancement New feature or request labels Nov 29, 2021
@bluwy
Copy link
Member

bluwy commented Nov 29, 2021

I don't quite understand your usecase linked to StackOverflow. An underscore prefix is the blessed way to opt out of routing, having another option causes two ways to do the same thing. Dynamic imports should still work with private modules, so I'm not sure if we need this new option.

@oliversturm
Copy link

I'm looking for a way to exclude routes, so that I can have extra routes in the project that are not included in a production build.

Currently I have a sub-folder src/routes/debug and all the extra "dev" routes are underneath it (the pages often contain specific test cases for components, similar to what one might do with the eternally incompatible storybook).

So I'd like to do something like this:

kit: {
  files: {
    routes: {
      path: 'src/routes',
      exclude: 'debug'
    }
  }
}

Alternatively - and I was surprised to find that this is not possible - I tried this:

kit: {
  files: {
    routes: ['src/routes', 'src/routes-debug']
  }
}

(Of course I would have then passed different values depending on dev vs production.)
This only results in an error though, because routes must be a single string.

The existing exclusion mechanism using the leading _ works well, but it does not apply at all for conditional scenarios like this.

@tony19
Copy link
Contributor Author

tony19 commented Jan 29, 2022

Fixed by #3576

Released in 1.0.0-next.249

@tony19 tony19 closed this as completed Jan 29, 2022
@autr
Copy link

autr commented Apr 29, 2023

I don't quite understand your usecase linked to StackOverflow. An underscore prefix is the blessed way to opt out of routing, having another option causes two ways to do the same thing. Dynamic imports should still work with private modules, so I'm not sure if we need this new option.

Said like religious fanatic ("blessed").

There is still no way to programmatically control routes or build output in SvelteKit. Whatever freedoms were once in the config file are gone.

Error: Unexpected option config.kit.package

Ad infinitum.

@autr autr mentioned this issue Apr 29, 2023
5 tasks
@fortserious
Copy link

Where did config.kit.routes go and what is the current method of excluding routes from a SvelteKit build?

@brunnerh
Copy link
Member

brunnerh commented Sep 28, 2024

It suspect that it was removed when the routing was switched to the +page system.
For the most part it should not be necessary to exclude anything because the components now need special names to be a route to begin with.

If you still need a feature like this, maybe a new issue should be opened (that also explains why you need it).

(You can also use the handle hook to intercept requests dynamically.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants