diff --git a/packages/adapter-node/README.md b/packages/adapter-node/README.md index ed176ebb3aee..8c04a5e06c44 100644 --- a/packages/adapter-node/README.md +++ b/packages/adapter-node/README.md @@ -14,13 +14,17 @@ export default { kit: { adapter: adapter({ // default options are shown below - outdir: 'build', - outfile: join(outdir, 'index.js') - bundle: true, - format: 'esm', - platform: 'node', - target: 'node12', - external: Object.keys(JSON.parse(readFileSync('package.json', 'utf8')).dependencies || {}), + out: 'build', + esbuildOptions: { + outdir: out, + bundle: true, + format: 'esm', + platform: 'node', + target: 'node12', + external: [ + /* package.json#dependencies */ + ] + } }) } }; @@ -28,9 +32,24 @@ export default { ## Options -All [esbuild build](https://esbuild.github.io/api/#build-api) options except for `entryPoints` are supported. +### out -The [outdir](https://esbuild.github.io/api/#outdir) is the directory to build the server to. It defaults to `build` — i.e. `node build` would start the server locally after it has been created. +The directory to build the server to. It defaults to `build` — i.e. `node build` would start the server locally after it has been created. + +### esbuildOptions + +Any custom [esbuild build](https://esbuild.github.io/api/#build-api) options. It defaults to: + +```js +{ + outdir: out /* = 'build' */, // Unless a outfile is specified + bundle: true, + format: 'esm', + platform: 'node', + target: 'node12', + external: [ /* package.json#dependencies */ ] +} +``` ## Environment variables diff --git a/packages/adapter-node/index.d.ts b/packages/adapter-node/index.d.ts index 0619704c5e91..b5c4c75a22cc 100644 --- a/packages/adapter-node/index.d.ts +++ b/packages/adapter-node/index.d.ts @@ -1,3 +1,6 @@ -declare function plugin(options?: import('esbuild').BuildOptions): import('@sveltejs/kit').Adapter; +declare function plugin(options?: { + out?: string; + esbuildOptions?: import('esbuild').BuildOptions; +}): import('@sveltejs/kit').Adapter; export = plugin; diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index 0adf9412247e..a2332af442b3 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -4,17 +4,24 @@ import { join } from 'path'; import { fileURLToPath } from 'url'; /** - * @param {import('esbuild').BuildOptions} options + * @param {{ + * out?: string, + * esbuildOptions?: import('esbuild').BuildOptions + * }} options */ export default function ({ - outdir = 'build', - outfile = join(outdir, 'index.js'), - bundle = true, - format = 'esm', - platform = 'node', - target = 'node12', - external = Object.keys(JSON.parse(readFileSync('package.json', 'utf8')).dependencies || {}), - ...esbuildOptions + out = 'build', + esbuildOptions: { + outfile, + outdir = typeof outfile === 'undefined' ? out : undefined, + bundle = true, + format = 'esm', + platform = 'node', + target = 'node12', + external = Object.keys(JSON.parse(readFileSync('package.json', 'utf8')).dependencies || {}), + entryPoints = ['.svelte-kit/node/index.js'], + ...esbuildOptions + } = {} } = {}) { /** @type {import('@sveltejs/kit').Adapter} */ const adapter = { @@ -22,7 +29,7 @@ export default function ({ async adapt({ utils, config }) { utils.log.minor('Copying assets'); - const static_directory = join(outdir, 'assets'); + const static_directory = join(out, 'assets'); utils.copy_client_files(static_directory); utils.copy_static_files(static_directory); @@ -38,7 +45,7 @@ export default function ({ platform, target, external, - entryPoints: ['.svelte-kit/node/index.js'], + entryPoints, define: { ...esbuildOptions.define, esbuild_app_dir: '"' + config.kit.appDir + '"' @@ -47,7 +54,7 @@ export default function ({ utils.log.minor('Prerendering static pages'); await utils.prerender({ - dest: `${outdir}/prerendered` + dest: `${out}/prerendered` }); } };