Skip to content

Commit

Permalink
BUNDLERS: fixing docs to include more complete vite-config info
Browse files Browse the repository at this point in the history
  • Loading branch information
getify committed Mar 26, 2024
1 parent 5f93d36 commit 6dc7876
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions BUNDLERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ import WALC from "@lo-fi/webauthn-local-client/bundlers/vite";
export default defineConfig({
// ..

plugins: [ WALC() ],
optimizeDeps: {
esbuildOptions: {
// WALC uses "top-level await", which is ES2022+
target: "es2022",
},
},

build: {
// WALC uses "top-level await", which is ES2022+
target: "es2022"
},

plugins: [ WALC() ],

// ..
});
```
Expand All @@ -55,11 +62,11 @@ This plugin works for the `vite dev` (dev-server), `vite preview` (also dev-serv

#### Top-level `await`

This library uses ["top-level `await`"](https://github.com/tc39/proposal-top-level-await), a feature added to JS in ES2022. The current default target for Vite seems to be browsers older than this, so the above config explicitly sets the `build.target` to `"es2022"`.
This library uses ["top-level `await`"](https://github.com/tc39/proposal-top-level-await), a feature added to JS in ES2022. The current default target for Vite seems to be browsers older than this, so the above config explicitly sets the *targets* to `"es2022"`.

You may experience issues where your tooling/configuration either ignores this setting, or otherwise breaks with it set. This may variously result in seeing an error about the top-level `await`s in this library being incompatible with the built-target, or an error about `await` needing to only be in `async function`s or the top-level of a module (which it is!).

Those types of errors generally indicate that you may need to configure Vite to skip trying to optimize the `walc.mjs` file during bundling, something like:
You may need to configure Vite to skip trying to optimize the `walc.mjs` file during bundling, something like:

```js
export default defineConfig({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@lo-fi/webauthn-local-client",
"description": "Browser-only utils for locally managing WebAuthn (passkey) API",
"version": "0.999.2",
"version": "0.999.3",
"exports": {
".": "./dist/bundlers/walc.mjs",
"./bundlers/vite": "./bundler-plugins/vite.mjs",
Expand Down

0 comments on commit 6dc7876

Please sign in to comment.