-
|
I bumped into Lit and it sounded closer to the metal than Vue, which I have some experience with, even if I'm mostly a backend developer. I hoped to find a similar framework but one which had less requirements on the development and build process. As Lit claims to be using native web components, functions and features, my expectation was that it would be straight forward to build it for the browser, as well as not requiring a custom language server for types. My experience so far is that it's hard to get the NPM package(s) to run in the browser without first running the project through a bundler. I'm used to using a bundler with Vue, but here I was specifically looking for something that depends less on various build tools and more on core browser tech, going away from specialized build tools like with Vue. Just using a bundler could be OK if I were to deploy the project after built, but the project I'm working on is for end users to download, customize, and build locally themselves, so I wanted to reduce the number of things that could go wrong, thus reducing the amount of tooling needed. Is it just not feasible to build a Lit project only using TSC, so that the project still can use TypeScript, without using any bundler or other tooling? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
Funny enough I actually got the NPM package to work straight with the browser by doing the below changes to imports in the library, which of course is not a reasonable solution as an update of the package would nuke all my local adjustments, this is mostly because I had to try.
A few minutes of project-wide search & replace and voila, it works! The page loads and at least the hello world custom tag with a reactive property works with zero warnings or errors. This is exactly what I want, but I am unfamiliar with package publishing, and if applying these changes will wreck compatibility with bundlers instead. In any case, I'll go through some tutorials now when I have a working dev environment and might report back here if I have to do more adjustments. |
Beta Was this translation helpful? Give feedback.
-
|
(as a side note, in the live project I was going to use this, I have a shared library that works both in Deno and in the browser, and now I noticed that for Deno it contains .*ts imports, which is not allowed when building for the browser, so now I need to configure Rollup, or use Vite that comes with that preconfigured, to build with working imports, so I guess this struggle was for naught as that will also work for Lit. An interesting exercise in any case, and I learned some things!) |
Beta Was this translation helpful? Give feedback.
You certainly can write your source code in TS, and use
tscto emit JS and use it directly.You should keep the bare module specifiers like
litas they are for your published package so users can supply their own copy from npm and use their own bundler for resolving/bundling them.For your own consumption and testing of your component, you can also use importmaps to resolve those bare module specifiers in the browser without doing a search and replace.
example https://stackblitz.com/edit/lit-importmap?file=index.html
Depending on other packages you use like directives and such, you may need to add more entries to the importmap. There might be tools that help you emit that importmap json t…