Skip to content

Implement minimal effort compromise to support Deno/ ESM #5003

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

Closed
5 tasks
lucidNTR opened this issue Jun 11, 2020 · 20 comments
Closed
5 tasks

Implement minimal effort compromise to support Deno/ ESM #5003

lucidNTR opened this issue Jun 11, 2020 · 20 comments

Comments

@lucidNTR
Copy link

Is your feature request related to a problem? Please describe.
Deno is slowly gaining traction and we see some requests to support svelte development from deno. However it was decided that maintaining a "native" ESM release next to the nodejs one would be too much work for the svelte team in the current setup.

Describe the solution you'd like
I propose a minimal effort compromise to allow supporting ESM/ deno based workflows by officially referring to available bridge software (snowpack and/or unpkg.com) and just maintaining the minimally needed changes in the svelte codebase that are necessary to run in such a setup without manual patching.

Describe alternatives you've considered
#4807:
"[...] removing the snowpack [eg. be available for deno in the pika registry] requirement would be more work to get right [...] It would require either package.json to support multiple module entry points, which it currently does not, or for us to find a way to export the compiler into the main module entry point without making esm importing browsers to import the compiler when not needing it. [...]

How important is this feature to you?
It would be most important to new developers that try out svelte + deno and all run into the same issues. If we minimally support this and also add a few sentences of documentation we could save each of these developers work and possibly duplicate issues or support requests on discord.

Implementation Details
There are currently two possibilities to do this

a) by using snowpack

  • add a compiler option to include a ".js" or ".mjs" file ending so the import in the esm compiled output will be
    ..} from "svelte/internal.(m)js";
    (as the probing for file extensions and handling of index.js files is nodejs specific)
    this could also be solved in a preprocessor step, but i think it is better to officially add the file ending when using the compiler with esm output
  • add a section to the svelte readme or the api docs or to the https://github.com/sveltejs/integrations repo how to use svelte with snowpack and deno, i would also create an example starter template and add my example deno/svelte build script

b) by using unpkg.com
this method is also compatible with a, the only downside is that it requires one more change to the svelte codebase compared to a) This additional change already has a PR here:
#4972

  • changes from a
  • add the compiler esm output to the nodejs package
  • add documentation in the appropriate place how to use unpkg.com to import the esm compiler
@antony
Copy link
Member

antony commented Jun 11, 2020

@lucidNTR with regards to sveltejs/integrations - tutorials / recipes / cookbooks tends to go on https://github.com/svelte-society/recipes-mvp

@lucidNTR
Copy link
Author

@antony cool, did not know that repo.
because it is a lot of text for a ticket, the summary what is needed to create a first PR:

  • decision if import file endings should be done in a preprocessor, svelte compiler option or changed standard output for the "esm" option
  • decide if merging Allow using the compiler as an ESM module #4972 is acceptable overhead for the svelte maintainers or not

@benmccann
Copy link
Member

@lucidNTR here are some other tickets where people are looking at Snowpack support in case it's helpful to you to find more collaborators on this: #4898 sveltejs/sapper#1204

@lucidNTR
Copy link
Author

lucidNTR commented Jun 11, 2020

@benmccann good point, thanks! i should clarify that i am not talking about general snowpack support for sapper/svelte, where snowpack acts as a rollup wrapper to do bundling and provide a dev server. This ticket here is only about the very small scope to use the "snowpack install" command to provide a deno compatible entry point. The actual implementation work required here is by design very minimal and i am happy to do it...

@Pierstoval
Copy link
Contributor

The actual work is mostly to be able to use a proper "bundler" with Deno. There is already the deno bundle command to generate a single JS output file, but this isn't really what rollup or webpack (or snowpack) do.

Looking at making Rollup compatible with Deno sounds like a first-class issue to me (since Rollup seems the default proposed solution to bundle a Svelte/Sapper app).

@diamondburned
Copy link

Can there be a way to use a custom bundler for this? It would be great if people could use esbuild.

@Pierstoval
Copy link
Contributor

Now that #4972 is merged, Svelte can be imported as ESM module, so we could use it as-is and start boostraping a Svelte project with deno 👍

@Taha-Firoz
Copy link

Now that #4972 is merged, Svelte can be imported as ESM module, so we could use it as-is and start boostraping a Svelte project with deno 👍

Can you please upload a mock-up of how it would be achieved. I hardly understand how sveltes build system works with Node and Rollup

@Pierstoval
Copy link
Contributor

Can you please upload a mock-up of how it would be achieved. I hardly understand how sveltes build system works with Node and Rollup

I first need to find time to work on that 😉

@softgripper
Copy link

I'm looking forward to this.

Native typescript in deno is a godsend, and if I can easily get svelte running in the mix that would be great.

Right now, package.json and the tsc stuff is really annoying - requiring error prone bootstrap files.. If deno and svelte just worked out of the box, I'd be very happy 👍

@kirawi
Copy link

kirawi commented Nov 2, 2020

Is this not yet fully working? I haven't tried it yet, but I don't see a confirmation of it working at all so far.

@peopledrivemecrazy
Copy link
Contributor

Is this not yet fully working? I haven't tried it yet, but I don't see a confirmation of it working at all so far.

A while back there was a PR #5605 you may have hints over there, Good luck.

@DougAnderson444
Copy link

@lucidNTR Now that #4972 is merged, have you been able to get this working without manual intervention?
Care to share an example / steps for those new to snowpack?

@DougAnderson444
Copy link

DougAnderson444 commented Nov 29, 2020

Anyone else else looking for this solution, it's being built here:

https://github.com/denofn/svelte/tree/master/example

@kirawi @softgripper @Pierstoval @lucidNTR

@lucidNTR
Copy link
Author

lucidNTR commented Dec 3, 2020

@DougAnderson444 Hi sorry for the late reply, i can confirm that
import { compile } from 'https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=raw/compiler.mjs'

in Deno imports without any errors and is able to compile all the svelte files i tried! I am still testing the resolution sub imports especially the missing file ending issue in the ticket

@buttercubz
Copy link

@DougAnderson444 Hi sorry for the late reply, i can confirm that
import { compile } from 'https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=raw/compiler.mjs'

in Deno imports without any errors and is able to compile all the svelte files i tried! I am still testing the resolution sub imports especially the missing file ending issue in the ticket

@lucidNTR I've been working on a small project(snel) for a while to compile svelte projects with deno, I was able to make the compiler work 100% in deno, the only problem I have now is the way I solve the imports of linked components, for now if you can use well. btw any contribution to the project is very helpful.

@Pierstoval
Copy link
Contributor

@buttercubz This is really interesting! Thanks for the link :)

@benmccann
Copy link
Member

#4972 was merged and there's an adapter-deno prototype for SvelteKit: sveltejs/kit#1271

As far as docs go, I'd suggest adding to https://github.com/sveltejs/integrations or https://sveltesociety.dev/. We try to document just the core API on svelte.dev since that's what the maintainers know and can reasonably be responsible for and prefer that the community handles all the other various platforms out there.

Is there anything left to do here or should we close this ticket?

@buttercubz
Copy link

#4972 was merged and there's an adapter-deno prototype for SvelteKit: sveltejs/kit#1271

As far as docs go, I'd suggest adding to https://github.com/sveltejs/integrations or https://sveltesociety.dev/. We try to document just the core API on svelte.dev since that's what the maintainers know and can reasonably be responsible for and prefer that the community handles all the other various platforms out there.

Is there anything left to do here or should we close this ticket?

i think can be closed, svelte/compiler works correctly in deno, adapters for svelte/kit are out of the original scope of this issue

@michael-spengler
Copy link

@buttercubz: I searched the www for this :)

Is there a state of the art best practice recommendation from snel side available? This would solve crewdevio/Snel#40 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests