-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Figured out how to use Vite to demo working on the component! I'm surprised I haven't figured this out yet, it works really well. This also finally allows everything to work locally, since it uses npm for loading the Constructable Stylesheets and ES Module Shims polyfills. Once the dev server is running in a terminal tab, note that you have to navigate specifically to `http://localhost:5500/test/index.html`, since the main HTML file isn't in the root of the project, because I want to use it only for testing things out. https://vitejs.dev/guide/#index-html-and-project-root I had to add `skipLibCheck` because the Constructable Stylesheets Polyfill has overlapping types with the standard library now, unfortunately. So everything was working good with Vite and all (type-wise), but the regular lib defintions were overlapping with each other, since TS natively added types for `document.adoptedStyleSheets`. I can look into making an issue/PR to the polyfill to make it work accordingly with newer TS versions. I had to add `?inline` to make Vite happy for the CSS Module Scripts import. I am going to look into a way to get around that issue, as I don't want to enforce needing to use that for users that don't use Vite. That query parameter could mean something else by chance on their server, or something like that. Oh yeah, and turns out I needed `rootDir`/`exclude` for the `tsconfig` because of each Web Component's use of `declare global { interface HTMLElementTagNameMap {} }`, since it defines the tag names on the global scope, and the output JS and types in `./dist` clash with the `./src` definitions, so that causes a type collision issue as well. Aag! I'm gonna look into seeing how Lit element components deal with that, maybe they also `exclude` the `dist` directory. I didn't want to use `rootDir` because I wanted to apply type checking to the TS files in `./test`, like how I'm doing for my other projects. That was one of the benefits with moving to Vite, that I can type check the demo files as well, and use full TS, and also not need to run `tsc` in parallel to the dev server. Instead the server (Vite) can handle the transpilation for me :) All about that simple abstraction :)
- Loading branch information
1 parent
c80c2eb
commit 8ca901d
Showing
10 changed files
with
593 additions
and
15 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
window.esmsInitOptions = { | ||
polyfillEnable: ["css-modules"] | ||
}; | ||
|
||
await import("construct-style-sheets-polyfill"); | ||
// @ts-expect-error - module types | ||
await import("es-module-shims"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
{ | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"outDir": "./dist", | ||
"module": "NodeNext", | ||
"target": "ESNext", | ||
"isolatedModules": true, | ||
"allowArbitraryExtensions": true, | ||
"types": [ | ||
"vite/client" | ||
], | ||
"noEmit": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"noImplicitOverride": true, | ||
"noPropertyAccessFromIndexSignature": true, | ||
"noUncheckedIndexedAccess": true, | ||
"allowUnreachableCode": false, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true | ||
} | ||
}, | ||
"exclude": [ | ||
"./dist" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { defineConfig } from "vite"; | ||
|
||
export default defineConfig({ | ||
base: "./", | ||
build: { | ||
target: "esnext" | ||
}, | ||
server: { | ||
port: 5500, | ||
strictPort: true | ||
}, | ||
preview: { | ||
port: 5500, | ||
strictPort: true | ||
} | ||
}); |