modernweb-dev / web

Guides, tools and libraries for modern web development.
https://modern-web.dev
MIT License
2.22k stars 289 forks source link

[dev-server] Default node resolution #1950

Open justinfagnani opened 2 years ago

justinfagnani commented 2 years ago

I think it'd be really helpful to have a default resolution mode for @web/dev-server, and for that default to be a new mode closer to Node module and browser w/ import maps resolution.

There are two main reasons I'd like a default mode:

  1. I have to pass --node-resolution every time I use WDS. Basically no project I've ever had works without it, so it's pure boilerplate.
  2. I want more users to use our Lit development builds, so I want the default to include the development export condition. This is a dev server after all :) and it would greatly improve DX for users to get our more extensive development build warnings. I hope this will be true of more projects that adopt export conditions of time too.

As for the mode, I really want a mode that resolves bare specifiers and package names, but not the rest of the path (except for when package exports are available). Node doesn't do path searching for modules, and import maps can't do suffix mappings, so the current node resolution can hide subtle mistakes where you intended to use a file extension, but forgot.

Westbrook commented 2 years ago

We namely leverage the Resolve plug-in from Rollup to power this in dev server. Have you raised this question there?

daKmoR commented 2 years ago

I also use @web/dev-server to check if a build output of an app actually would work on a "default web server".

So I do

  1. Developing web-dev-server --node-resolve ./page
  2. Build it rollup ...
  3. Check build web-dev-server ./_site

it usually comes back to the question... do we wanna have a "magical" thing that just works... and you may have a surprise as you push it to a real server (e.g. if it "just" works - you may be inclined to just push your source)

so as you provide the option you are at least aware that your server will need to have the same option/functionality or you need to transform your code so that this functionality is no longer needed...

always a balancing act 😅

here is a crazy idea - ship "2 clis/servers"?

justinfagnani commented 1 year ago

I hit this again today when I forgot that Web Dev Server does not set the development condition by default. I think a lot of other developer tools are doing this by default now (Vite and Next?) and it's a bit weird that a "dev" server isn't.

It's also cumbersome to have to write a config file to set the option. I think for a dev server this should just happen out of the box.

justinfagnani commented 1 year ago

What do people think about adding "development" by default as I did in #2109?

I think if you're trying to use the dev server as a stand-in for a prod server there's already so many things that are different - you're not using your same build pipeline! - that using the development condition is just one small thing. Also most libraries that bother publishing a development export should be assuring that the behavior is the same or more strict in dev builds.

If something doesn't work, the user can make a config file with the development condition omitted.