Skip to content

Commit 4ecc59b

Browse files
committed
add bundler testbed
1 parent e586a10 commit 4ecc59b

File tree

13 files changed

+680
-432
lines changed

13 files changed

+680
-432
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ smithy-typescript-codegen-test/bin/
4040
smithy-typescript-ssdk-codegen-test-utils/bin/
4141
smithy-typescript-codegen-test/example-weather-customizations/bin/
4242

43+
testbed/bundlers/dist
44+
testbed/bundlers/dist-min
4345
**/node_modules/
4446
**/*.tsbuildinfo
4547
**/*.d.ts

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ test-unit:
3131
test-browser:
3232
yarn g:vitest run -c vitest.config.browser.mts
3333

34+
test-bundlers:
35+
(cd ./testbed/bundlers && make build test)
36+
3437
# typecheck for test code.
3538
test-types:
3639
npx tsc -p tsconfig.test.json

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@types/jsdom": "20.0.1",
4242
"@typescript-eslint/eslint-plugin": "8.32.0",
4343
"@typescript-eslint/parser": "8.32.0",
44-
"esbuild": "0.19.11",
44+
"esbuild": "^0.25.9",
4545
"eslint": "8.57.0",
4646
"eslint-plugin-simple-import-sort": "7.0.0",
4747
"eslint-plugin-tsdoc": "0.2.17",
@@ -54,8 +54,10 @@
5454
"ts-jest": "29.1.2",
5555
"turbo": "2.3.3",
5656
"typescript": "~5.8.3",
57+
"vite": "^7.1.4",
5758
"vitest": "^3.2.4",
58-
"webpack": "5.91.0"
59+
"webpack": "^5.101.3",
60+
"webpack-cli": "^6.0.1"
5961
},
6062
"overrides": {},
6163
"workspaces": [

testbed/bundlers/Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.PHONY: test build vite webpack
2+
3+
# asserts that bundles contain expected content.
4+
test:
5+
node bundlers.spec.mjs
6+
du -sh ./dist-min/*
7+
8+
# create bundles
9+
build:
10+
rm -rf ./dist/*
11+
rm -rf ./dist-min/*
12+
make vite webpack
13+
14+
# note: vite deletes files in the build folders and must run first.
15+
vite:
16+
npx vite build --config vite.config.ts
17+
npx vite build --config vite.min.config.ts
18+
19+
webpack:
20+
npx webpack
21+
npx webpack -c webpack.min.config.js
22+
23+
esbuild:
24+
exit 1

testbed/bundlers/bundlers.spec.mjs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import assert from "node:assert";
2+
3+
import fs from "node:fs";
4+
import path from "node:path";
5+
import { fileURLToPath } from "node:url";
6+
7+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
8+
9+
const webpackDist = {
10+
name: "webpack",
11+
content: fs.readFileSync(path.join(__dirname, "dist", "webpack-dist.js"), "utf-8"),
12+
};
13+
const viteDist = {
14+
name: "vite",
15+
content: fs.readFileSync(path.join(__dirname, "dist", "vite-dist.js"), "utf-8"),
16+
};
17+
18+
for (const { content: fileContents, name } of [webpackDist, viteDist]) {
19+
console.log("================", name, "================");
20+
21+
const contentSize = fileContents.replaceAll(/\s+/g, "").length;
22+
const callsToClassBuilder = fileContents.match(/\.classBuilder\(\)/g) || [];
23+
24+
const serializers = fileContents.match(/(var|const) se_/g) || [];
25+
const operationSchemas = fileContents.match(/ op\(/g) || [];
26+
const structSchemas = fileContents.match(/ struct\(/g) || [];
27+
28+
console.log("serializers", serializers.length);
29+
console.log("operationSchemas", operationSchemas.length);
30+
console.log("structSchemas", structSchemas.length);
31+
}

testbed/bundlers/esbuild.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import esbuild from "esbuild";
2+
3+
const buildOptions = {
4+
platform: "browser",
5+
target: ["es2020"],
6+
bundle: true,
7+
format: "esm",
8+
mainFields: ["module", "browser", "main"],
9+
allowOverwrite: true,
10+
entryPoints: ["./source.ts"],
11+
supported: {
12+
"dynamic-import": true,
13+
},
14+
outfile: "./dist/esbuild-dist.js",
15+
keepNames: true,
16+
external: [],
17+
};
18+
19+
await esbuild.build(buildOptions);

testbed/bundlers/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"dependencies": {},
3+
"type": "module"
4+
}

testbed/bundlers/source.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { SmithyRpcV2CborProtocol } from "@smithy/core/cbor";

testbed/bundlers/vite.config.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { defineConfig } from "vite";
2+
import * as path from "node:path";
3+
4+
export default defineConfig({
5+
build: {
6+
outDir: "./dist",
7+
lib: {
8+
entry: path.join(__dirname, "source.ts"),
9+
name: "dist",
10+
// the proper extensions will be added
11+
fileName: "vite-dist",
12+
},
13+
rollupOptions: {
14+
// make sure to externalize deps that shouldn't be bundled
15+
// into your library
16+
external: [],
17+
output: {
18+
// Provide global variables to use in the UMD build
19+
// for externalized deps
20+
globals: {},
21+
// to get an easier aggregate accounting of bundle contents
22+
inlineDynamicImports: true,
23+
},
24+
},
25+
minify: false,
26+
terserOptions: {
27+
mangle: false,
28+
},
29+
},
30+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { defineConfig } from "vite";
2+
import * as path from "node:path";
3+
4+
export default defineConfig({
5+
build: {
6+
outDir: "./dist-min",
7+
lib: {
8+
entry: path.join(__dirname, "source.ts"),
9+
name: "dist-min",
10+
// the proper extensions will be added
11+
fileName: "vite-dist.min",
12+
},
13+
rollupOptions: {
14+
// make sure to externalize deps that shouldn't be bundled
15+
// into your library
16+
external: [],
17+
output: {
18+
// Provide global variables to use in the UMD build
19+
// for externalized deps
20+
globals: {},
21+
// to get an easier aggregate accounting of bundle contents
22+
inlineDynamicImports: true,
23+
},
24+
},
25+
minify: true,
26+
terserOptions: {
27+
mangle: true,
28+
},
29+
},
30+
});

0 commit comments

Comments
 (0)