-
Notifications
You must be signed in to change notification settings - Fork 41
Integrating Svelte? #351
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
Comments
Sounds like a great idea! Perhaps we can mimic svelte-add/coffeescript? Or is svelte-add still active / the right approach? Let us know if you'd like to work on this; it doesn't look too difficult. |
We'll need to add support for |
Looking at Svelte's TypeScript support, the transpilation may be possible now with our existing Vite plugin which should also work as a Rollup plugin. But obviously this needs testing. |
Not sure if it is the right approach. But I can experiment with mimicing the svelte-add coffeescript and see what happens. |
Great! Feel free to suggest a better approach as well if you find one. FYI, we've added support for |
There is a bit learning curve here. My WIP version: |
Update: BTW, the |
@levitabris Have you taken a look at our new Rollup and Vite plugins? https://github.com/DanielXMoore/Civet/tree/main/integration/unplugin/examples please try them out and let us know if you have any questions or encounter any errors, thanks! |
Hey, any updates or use-cases with svelte? All I found is an attempt https://github.com/moka-ayumu/svelte-civet 2 years ago |
@edemaine, could you explain the reason for the dislike reaction? I saw that others have also attempted to make the svelte-preprocess work with Civet dependencies (as seen in sveltejs/svelte-preprocess#627 and sveltejs/svelte-preprocess#600). Could you shed some light on your perspective? |
Sorry, I was being too concise. By 👎 I just meant "no, there haven't been any updates". It's still very much of interest, but we haven't heard any news since the last on this thread. It'd be great if you (or anyone) would be willing to try pushing this forward! |
New Svelte is pretty much Solid.JS, Svelte lost its unique features, I personally not going to use Svelte anymore, and I think I'm not alone, many people are disliking the new Svelte, so, probably it would became even less popular. |
Hey, quick update - made it work with preprocessor+civet devdependency https://github.com/adam2am/svelte-preprocess-with-civet / npm install svelte-preprocess-with-civet and setting up
But, svelte’s “runes” ($state, $effect, etc.) are purely a feature of the Svelte compiler, and at the moment the compiler only looks for them in files ending in: Even though you can write Civet‐style TypeScript in a .civet modulse, importing it as .civet never invokes the Svelte compiler, so any $state calls in there will still be treated as plain JavaScript (and you’ll get “rune_outside_svelte” errors). And wrapping your Civet file in the Vite plugin to output a virtual .svelte.js is an idea, but today the Civet unplugin only “loads” files whose IDs end in .civet or .civet.jsx/.civet.tsx. If you tell it to emit .svelte.js, its loadInclude() test doesn’t catch that, so Vite simply tries to read class.svelte.civet.svelte.js off disk and fails. => 15:28:44 [vite] (ssr) Error when evaluating SSR module /src/routes/+page.svelte: Failed to load url /src/routes/class.svelte.civet.svelte.js Does the file exist?
|
Updating the unplugin should indeed be straightforward! To clarify, I take it you're using the (not really tested) |
On it, and kinda connected it, it somewhat works, but TLDR: ✅ $state and import from .svelte.civet = works, I can use states, it's reactive even within .civet, website works ✅❔ script lang="civet" inside of +page.svelte = works, ❔IDE recognition issue: typescript imports are not dynamically updating stuff, import modules from .svelte.civet within +page.svelte are not being recognized out of the box and have no idea how to fix it, ?only manually setting up global.d.ts? ❔In vite.config.ts plugins: [ civetVitePlugin ] as any / as unknown as PluginOption, is a temporary workaround; ideally, we’d fix the TypeScript definitions upstream repos: Here's what I did: 1. In
- isCivetTranspiled := /(\.civet)(\.[jt]sx)?([?#].*)?$/
+ isCivetTranspiled := /(\.civet)(\.(?:[jt]sx|svelte\.(?:js|ts)))?([?#].*)?$/
- .replace(/\.[jt]sx$/, '')
+ .replace(/\.(?:[jt]sx|svelte\.(?:js|ts))$/, '') 2. Built and linked it to my project. In my project:
import civetVitePlugin from '@danielx/civet/vite';
export default defineConfig({
plugins: [
civetVitePlugin({
outputExtension: '.svelte.js',
ts: 'esbuild',
}) as any,
],
}); 3. import { sveltePreprocess } from 'svelte-preprocess-with-civet';
const config = {
preprocess: sveltePreprocess({
civet: { sync: true },
}),
};
export default config; Problem/question now:
|
Svelte is gaining popularity among people who appreciate simplicity and easy composability. Since its functionality is not based on a js import, would you consider making Civet compatible with .svelte components?
I would recommend a syntax like the following:
<script lang="civet"> 'hello world!' |> console.log </script>
The text was updated successfully, but these errors were encountered: