Skip to content
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

Merged
merged 2 commits into from Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -49,11 +49,12 @@
"check": "yarn lint:check && yarn prettier:check",
"fix": "yarn lint:fix && yarn prettier:fix",
"clean": "rm -rf lib/* deno/lib/*",
"build": "yarn run clean && npm run build:cjs && npm run build:esm && npm run build:deno",
"build": "yarn run clean && npm run build:cjs && npm run build:esm && npm run build:deno && yarn run build:tweak-dts",
"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",
Copy link
Collaborator

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?

Copy link
Contributor Author

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?

Copy link
Collaborator

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?

Copy link
Contributor Author

@rinsuki rinsuki Apr 7, 2022

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))

"rollup": "rollup --config rollup.config.js",
"test": "jest --coverage",
"test:deno": "cd deno && deno test",
Expand Down
6 changes: 6 additions & 0 deletions rollup.config.js
Expand Up @@ -10,6 +10,12 @@ export default [
format: "es",
sourcemap: false,
},
{
file: "lib/index.umd.js",
name: "Zod",
format: "umd",
sourcemap: false,
},
],
plugins: [
typescript({
Expand Down