mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 12:57:47 +00:00
[next] Add @vercel/next Builder (#7793)
This commit is contained in:
46
packages/next/scripts/build-edge-function-template.js
Normal file
46
packages/next/scripts/build-edge-function-template.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const { build } = require('esbuild');
|
||||
const assert = require('assert');
|
||||
const { outputFile } = require('fs-extra');
|
||||
|
||||
/**
|
||||
* @param {Pick<import('esbuild').BuildOptions, 'outfile' | 'format' | 'entryPoints' | 'write'>} options
|
||||
*/
|
||||
async function buildTemplate(options) {
|
||||
return build({
|
||||
bundle: true,
|
||||
entryPoints: options.entryPoints,
|
||||
format: options.format,
|
||||
legalComments: 'none',
|
||||
minify: process.env.NODE_ENV !== 'test',
|
||||
outfile: options.outfile,
|
||||
// Cloudflare Workers uses the V8 JavaScript engine from Google Chrome.
|
||||
// The Workers runtime is updated at least once a week, to at least the version
|
||||
// that is currently used by Chrome's stable release.
|
||||
// To see the latest stable chrome version: https://www.chromestatus.com/features/schedule
|
||||
target: 'esnext',
|
||||
write: options.write,
|
||||
});
|
||||
}
|
||||
|
||||
async function buildNextjsWrapper() {
|
||||
const { outputFiles } = await buildTemplate({
|
||||
entryPoints: ['./src/edge-function-source/get-edge-function'],
|
||||
outfile: 'dist/___get-nextjs-edge-function.js',
|
||||
format: 'cjs', // https://esbuild.github.io/api/#format
|
||||
write: false,
|
||||
});
|
||||
|
||||
assert(outputFiles);
|
||||
const [src] = outputFiles;
|
||||
|
||||
return outputFile(src.path, `module.exports = ${JSON.stringify(src.text)}`);
|
||||
}
|
||||
|
||||
module.exports = buildNextjsWrapper;
|
||||
|
||||
if (!module.parent) {
|
||||
buildNextjsWrapper().catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user