-
Notifications
You must be signed in to change notification settings - Fork 7
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
[BUG] Webpack bundles typescript package when ts-runtime-checks is used #39
Comments
You could configure webpack to not bundle the library with the externals: {
"ts-runtime-checks": '...',
}, alternatively, you can declare the function yourself: export declare function myCheckFn<T, _rawErrorData extends boolean = false, _M = { __$marker: "check" }>(prop: unknown) : [T, Array<_rawErrorData extends true ? ValidationError : string>]; so you end up importing only types from the library and therefore it doesn't get bundled. |
This works! I’m considering migrating to Rollup, which has a better tree-shaking algorithm. Tbh, I use Webpack in this project just because I inherited it. Anyway, thanks for the quick answer and this awesome project! |
Hm, I have the same problem with Rollup, so it’s not Webpack-specific. |
I’m looking into your code, and now understand why it’s happening. It’s needed to clearly separate the build-time code (transformer) and runtime code (actually just type declarations). |
A better workaround (but still just a mere workaround): ts-runtime-checks.ts: // Workaround for https://github.com/GoogleFeud/ts-runtime-checks/issues/39
import type {
check as checkFn,
createMatch as createMatchFn,
is as isFn,
} from 'ts-runtime-checks'
export type * from 'ts-runtime-checks'
export declare const check: typeof checkFn
export declare const createMatch: typeof createMatchFn
export declare const is: typeof isFn |
whenever i attempt to use any of the lower cased methods from |
Describe the bug
I’m using Webpack to bundle a TypeScript project into a single JS file that can be executed with Node.js. When I import and use the
check
function fromts-runtime-checks
, I end up with a huge bundle that includes eventypescript.js
.Expected behavior
Development dependencies should not be bundled.
Additional context
Relevant devDependencies:
tsconfig.json:
webpack.config.mjs:
The text was updated successfully, but these errors were encountered: