Way to include additional scripts/entrypoints in final build (as is possible in pure Vite)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the problem
In pure Vite, you can define additional entrypoints to created by using library mode. However, because SvelteKit overrides the build process using its adapters and Vite plugin, nothing happens if you try to add these library entrypoints to your Vite config.
The reason I want this is because I have a one-time action I want to run after deploying to production. I want to write a script for that which relies on code already in my SvelteKit app (related to running operations on the database) that is then also included in the production build.
Describe the proposed solution
Respect Vite's library mode in all adapters and, next to the standard "index.js" and "handler.js", also include the scripts defined in the Vite config. So something like this:
export default defineConfig({
plugins: [sveltekit()],
build: {
lib: {
entry: {
kv: "./src/scripts/fill_kv.ts",
},
formats: ["es"],
},
},
});
Should create a script called "kv.js" alongside "index.js" in the build output.
Alternatives considered
- Building my own adapter: I believe this is a high maintenance cost for a pretty simple feature (that already works in pure Vite)
- Transpiling outside of Vite (e.g. with ts-node). This doesn't work, primarily because of the use of the import aliases which only SvelteKit knows about. Duplicating that in my tsconfig doesn't sound great either.
- Spinning off all logic necessary for the script/entrypoint into a separate library. Again high maintenance cost for code that 99.9% should just run on routes, but the occasional times needs to be run manually.
- Call the code using a route. I'd rather not have to create a special protected route just to run my code, when I have access to the actual server and the code is sitting right there.
Importance
nice to have
Additional Information
If anyone has any better solutions than the alternatives already listed, please let me know.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how the adapters and SvelteKit Vite plugin produce the standard index.js and handler.js outputs, then compare that flow with Vite library mode and its configured entry object. Check whether each adapter has separate output handling. Done means configured additional entrypoints are emitted alongside the standard build outputs across all adapters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, vite
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100