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
Add UMD build #1067
Add UMD build #1067
Conversation
package.json
Outdated
"build:deno": "node ./deno/build.mjs", | ||
"build:esm": "rollup --config rollup.config.js", | ||
"build:cjs": "tsc --p tsconfig.cjs.json", | ||
"build:types": "tsc --p tsconfig.types.json", | ||
"build:tweak-dts": "echo 'export as namespace Zod;' >> lib/index.d.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there something we can do in the source to get this same effect without having to patch the artifact?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find way to do it without patch to generated dts! can you review it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely better! Can you give me a little context as to why we need to export a namespace for the UMD target? Is that because it adds a global binding to the library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that because it adds a global binding to the library?
Yes!
FYI: If project uses module (like import ...
), global binding will be disabled on tsc (tsc says 'Zod' refers to a UMD global, but the current file is a module. Consider adding an import instead.ts(2686)
)
@rinsuki I'd rather the name of the global namespace be |
|
Add UMD build to zod.
Example
with UMD build, you can use zod on web browser without bundler/ESM support, like this:
Background
I want to use zod in UserScript, but I have some issues:
so I added a UMD build to Zod, which allows UserScript to use
@require
to load zod, like// @require https://some.cdn.like.jsdelivr.example/npm/zod@x.x.x/lib/index.umd.js
.