svelte-add
svelte-add copied to clipboard
Problem with coffeescript adder
originally posted in https://github.com/babichjacob/finite/issues/1:
The page says to use <script lang="coffee"> to enter CoffeeScript. However, that didn't work for me at all. On a lark, I tried changing it to <script type="coffee"> and, magically, it started working. You might want to check that README.
I opened a related issue on SvelteKit. <script type="coffee"> is the deprecated syntax, but unfortunately Vite does not process it properly so the CoffeeScript is actually treated as JS.
https://github.com/sveltejs/kit/issues/2920#issuecomment-996469815
To wrap up the state of CoffeeScript with SvelteKit/Vite. Currently, VIte handles pre-bundling scans for HTML-ish files, like Vue and Svelte, and they have a hardcoded way to transform them into JS. This however only works for JS/TS scripts which is based on esbuild's default loader. To have Vite support CoffeeScript, it'd need to have an esbuild plugin for it and interprets the script through the plugin. Otherwise, Vite would need to rework how it handles this case generically. And both aren't trivial tasks.
I'm commenting here to link this to the docs. And closing this as there's not much to fix in SvelteKit side. Feel free to open an issue over at VIte to support this feature though.
A work-around is to use external coffeescript files instead of inlining the coffeescript in the svelte file.
More info here: https://github.com/sveltejs/kit/issues/2920#issuecomment-1030223220
I'm going to close this, as this is nothing we can do to avoid this. As suggest in the linked kit issue, we require upstream changes for this to work