Replies: 6 comments 13 replies
-
this is neither a bug nor a feature request so i am going to convert it to a discussion. |
Beta Was this translation helpful? Give feedback.
-
#!/usr/bin/env node
console.log("Hello CLI")
Using esm ( If for whatever reason you absolutely need to use cjs - disclaimer: i do not recommend it.
{"type":"commonjs"} now cli.js will be treated as commonjs (require instead of import) after you repackaged it |
Beta Was this translation helpful? Give feedback.
-
But what about CLI scripts for a build version of the site (created via bin/deleteOldUsers.js
Is there any solution for this in SvelteKit? |
Beta Was this translation helpful? Give feedback.
-
I couldn't figure out how to build CLIs in my SvelteKit repo, couldn't figure out how to run jest against backend code, couldn't figure out how to share backend and frontend code that had to use different tsconfigs, and couldn't get a monorepo working with SvelteKit to let me do these things either. As a result, we did not use SvelteKit. That was with a version 6 months ago, so I don't know where things stand now. |
Beta Was this translation helpful? Give feedback.
-
I had the same problem and found a trick: adding an empty package.json to the CLI's outDir. In your package.json:
|
Beta Was this translation helpful? Give feedback.
-
I spent about 6 months this year on-and-off exploring this problem, collecting my notes, and writing a series of articles. I'm now running a SvelteKit project in a monorepo that also has command line tools that shares code with SvelteKit. This is how I do it. Please let me know of any issues you find. |
Beta Was this translation helpful? Give feedback.
-
Describe the problem
I have not been able to find a way to build standalone CLI executables from
.ts
in svelte-kit due to the"type":"module"
assignment inpackage.json
. No customtsconfig.tools.json
seems to do the job, and folks on discord (Svelte or TypeScript) and SO don't seem to know how to help.My app requires a separate tool for adding the admin user to the database (can't be done in SQL), and it requires a separate tool, run as a daemon, for periodically downloading data into the database.
The svelte-kit site and both tools need access to a significant amount of the same
.ts
code.In order for me to make further progress, it seems that because I decided to go with svelte-kit, I'm having to split out code needed in CLIs to a separate repo. (I also have a vanilla Svelte app for Electron which doesn't have this problem.)
But I'd rather keep everything in the same repo. If this is actually possible to do in svelte-kit, it would be nice to see it documented. If it's not currently possible, it would be nice if it were possible.
Describe the proposed solution
I have no idea how to do this.
UPDATE: I have found a flexible way to accomplish this and wrote a 4-part series on the topic: https://javascript.plainenglish.io/sharing-typescript-with-nx-and-turborepo-part-1-introduction-to-monorepos-d8d54b805e46
Alternatives considered
No response
Importance
would make my life easier
Additional Information
No response
Beta Was this translation helpful? Give feedback.
All reactions