Skip to content

Commit

Permalink
[static-build] Use esbuild (#10462)
Browse files Browse the repository at this point in the history
Switch to using esbuild to compile + bundle `@vercel/static-build`.
  • Loading branch information
TooTallNate committed Sep 8, 2023
1 parent 50e04dd commit b265e13
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-carrots-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/static-build': patch
---

Build package using "esbuild"
19 changes: 0 additions & 19 deletions packages/static-build/build.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/static-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"directory": "packages/static-build"
},
"scripts": {
"build": "node build",
"build": "node ../../utils/build-builder.mjs",
"test": "jest --reporters=default --reporters=jest-junit --env node --verbose --bail --runInBand",
"test-unit": "pnpm test test/build.test.ts test/gatsby.test.ts test/prepare-cache.test.ts",
"test-e2e": "pnpm test test/integration-*.test.js"
Expand Down
9 changes: 5 additions & 4 deletions packages/static-build/src/utils/gatsby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { isErrnoException } from '@vercel/error-utils';
import fs from 'fs-extra';
import * as path from 'path';
import semver from 'semver';
import { createRequire } from 'module';
import { fileExists } from './_shared';

const PLUGINS = [
Expand All @@ -13,14 +14,14 @@ type PluginName = typeof PLUGINS[number];
const GATSBY_CONFIG_FILE = 'gatsby-config';
const GATSBY_NODE_FILE = 'gatsby-node';

const require_ = createRequire(__filename);

const PLUGIN_PATHS: Record<PluginName, string> = {
'@vercel/gatsby-plugin-vercel-analytics': path.dirname(
eval('require').resolve(
`@vercel/gatsby-plugin-vercel-analytics/package.json`
)
require_.resolve(`@vercel/gatsby-plugin-vercel-analytics/package.json`)
),
'@vercel/gatsby-plugin-vercel-builder': path.dirname(
eval('require').resolve(`@vercel/gatsby-plugin-vercel-builder/package.json`)
require_.resolve(`@vercel/gatsby-plugin-vercel-builder/package.json`)
),
};

Expand Down
20 changes: 20 additions & 0 deletions utils/build-builder.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* This script is the build configuration common to all our Builder packages.
* We bundle the output using `esbuild`, and do not publish type definitions.
*
* `@vercel/build-utils` is marked as external because it's always an implicit
* dependency when the Builder is invoked by `vercel build`.
*/
import { join } from 'node:path';
import { readFileSync } from 'node:fs';
import { esbuild } from './build.mjs';

const pkgPath = join(process.cwd(), 'package.json');
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));

const externals = Object.keys(pkg.dependencies || {});

await esbuild({
bundle: true,
external: ['@vercel/build-utils', ...externals],
});

0 comments on commit b265e13

Please sign in to comment.