Skip to content

Commit 373aad5

Browse files
authored
fix: reduce bundle size of function script (#42)
1 parent 54da8cc commit 373aad5

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

packages/kysely-tailordb-codegen/build.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,14 @@ const getInjectContent = (globalName, globalInject) => {
6161
return `import { ${exportName} } from "${moduleSpecifier}"; globalThis.${globalName} = ${exportName};`;
6262
};
6363

64-
// Due to the use of dynamic require, bundling `git-diff` is difficult.
65-
// However, since it's not used in this use case, we can mock it instead.
66-
const mockGitDiff = {
67-
name: "mock-git-diff",
64+
// Mock packages that are difficult to bundle and not used in the current use case.
65+
const mockPackages = {
66+
name: "mock-packages",
6867
setup(build) {
69-
build.onResolve({ filter: /^git-diff$/ }, (args) => {
70-
return { path: args.path, namespace: "git-diff" };
68+
build.onResolve({ filter: /^(git-diff|cosmiconfig)$/ }, (args) => {
69+
return { path: args.path, namespace: "mock-packages" };
7170
});
72-
build.onLoad({ filter: /.*/, namespace: "git-diff" }, () => {
71+
build.onLoad({ filter: /.*/, namespace: "mock-packages" }, () => {
7372
return { contents: "export default null" };
7473
});
7574
},
@@ -84,7 +83,7 @@ build({
8483
define: {
8584
global: "globalThis",
8685
},
87-
plugins: [unenvAlias, unenvInject, mockGitDiff],
86+
plugins: [unenvAlias, unenvInject, mockPackages],
8887
// Unused drivers are left unbundled as-is.
8988
// Note that future updates to `kysely-codegen` may introduce new drivers.
9089
external: [

packages/kysely-tailordb-codegen/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tailor-platform/function-kysely-tailordb-codegen",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Generate Kysely code for TailorDB",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)