Skip to content

Commit

Permalink
Add a test package for building bundles to assess total bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
airhorns committed Jul 24, 2023
1 parent d72033c commit 9f12967
Show file tree
Hide file tree
Showing 8 changed files with 5,410 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@
"@gadgetinc/api-client-core": "workspace:*",
"@gadgetinc/react": "workspace:*"
}
}
},
"dependencies": {}
}
47 changes: 47 additions & 0 deletions packages/test-bundles/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import react from "@vitejs/plugin-react-swc";
import fs from "fs";
import { join, parse } from "path";
import { visualizer } from "rollup-plugin-visualizer";
import { fileURLToPath } from "url";
import { build } from "vite";

const bundleDir = fileURLToPath(new URL("bundles", import.meta.url));
const entrypoints = fs.readdirSync(bundleDir);
console.log({ bundleDir, entrypoints });

for (const entrypoint of entrypoints) {
const parsed = parse(entrypoint);
const name = parsed.name;

const visualizerPlugin = visualizer({
emitFile: true,
filename: `${name}-stats.html`,
template: "treemap",
brotliSize: true,
gzipSize: true,
});
const plugins = parsed.ext.endsWith("x") ? [react(), visualizerPlugin] : [visualizerPlugin];

await build({
plugins,
build: {
lib: {
entry: join(bundleDir, entrypoint),
name: `test-bundle-${name}`,
fileName: `test-bundle-${name}`,
formats: ["es", "cjs"],
},
emptyOutDir: false,
rollupOptions: {
external: ["react", "react-dom"],
output: {
// Provide global variables to use in the UMD build
// for externalized deps
globals: {
react: "React",
},
},
},
},
});
}
6 changes: 6 additions & 0 deletions packages/test-bundles/bundles/api-read.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Client } from "@gadget-client/related-products-example";
const api = new Client();

export const read = async () => {
await api.shopifyProduct.findMany();
};
8 changes: 8 additions & 0 deletions packages/test-bundles/bundles/react-read.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Client } from "@gadget-client/related-products-example";
import { useFindMany } from "@gadgetinc/react";
const api = new Client();

export const Reader = () => {
const [{ data }] = useFindMany(api.shopifyProduct);
return <>{JSON.stringify(data)}</>;
};
24 changes: 24 additions & 0 deletions packages/test-bundles/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "test-bundles",
"version": "0.1.0",
"private": true,
"source": "src/index.ts",
"repository": "github:gadget-inc/js-clients",
"type": "module",
"scripts": {
"typecheck": "tsc --noEmit",
"build": "ts-node --transpileOnly --esm build.ts",
"prepublishOnly": "pnpm build",
"prerelease": "gitpkg publish"
},
"dependencies": {
"@gadgetinc/api-client-core": "workspace:*",
"@gadgetinc/react": "workspace:*",
"@gadgetinc/react-shopify-app-bridge": "workspace:*",
"@vitejs/plugin-react-swc": "^3.3.2",
"vite": "^4.4.7"
},
"devDependencies": {
"rollup-plugin-visualizer": "^5.9.2"
}
}
4,838 changes: 4,838 additions & 0 deletions packages/test-bundles/stats.html

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions packages/test-bundles/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "es2020",
"module": "ESNext",
"lib": ["es2020", "DOM"],
"noEmit": true,
"skipLibCheck": true,
"declaration": false
}
}
Loading

0 comments on commit 9f12967

Please sign in to comment.