mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-08 12:57:46 +00:00
[static-build] Use esbuild (#10462)
Switch to using esbuild to compile + bundle `@vercel/static-build`.
This commit is contained in:
5
.changeset/moody-carrots-know.md
Normal file
5
.changeset/moody-carrots-know.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@vercel/static-build': patch
|
||||
---
|
||||
|
||||
Build package using "esbuild"
|
||||
@@ -1,19 +0,0 @@
|
||||
const execa = require('execa');
|
||||
const { remove } = require('fs-extra');
|
||||
|
||||
async function main() {
|
||||
await remove('dist');
|
||||
|
||||
await execa('tsc', [], { stdio: 'inherit' });
|
||||
|
||||
await execa(
|
||||
'ncc',
|
||||
['build', 'src/index.ts', '-e', '@vercel/build-utils', '-o', 'dist'],
|
||||
{ stdio: 'inherit' }
|
||||
);
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -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"
|
||||
|
||||
@@ -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 = [
|
||||
@@ -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`)
|
||||
),
|
||||
};
|
||||
|
||||
|
||||
20
utils/build-builder.mjs
vendored
Normal file
20
utils/build-builder.mjs
vendored
Normal file
@@ -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],
|
||||
});
|
||||
Reference in New Issue
Block a user