Skip to content

Commit dfae928

Browse files
committed
fix: use esbuildOptions parameter
1 parent ed6b445 commit dfae928

File tree

3 files changed

+51
-22
lines changed

3 files changed

+51
-22
lines changed

packages/adapter-node/README.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,42 @@ export default {
1414
kit: {
1515
adapter: adapter({
1616
// default options are shown below
17-
outdir: 'build',
18-
outfile: join(outdir, 'index.js')
19-
bundle: true,
20-
format: 'esm',
21-
platform: 'node',
22-
target: 'node12',
23-
external: Object.keys(JSON.parse(readFileSync('package.json', 'utf8')).dependencies || {}),
17+
out: 'build',
18+
esbuildOptions: {
19+
outdir: out,
20+
bundle: true,
21+
format: 'esm',
22+
platform: 'node',
23+
target: 'node12',
24+
external: [
25+
/* package.json#dependencies */
26+
]
27+
}
2428
})
2529
}
2630
};
2731
```
2832

2933
## Options
3034

31-
All [esbuild build](https://esbuild.github.io/api/#build-api) options except for `entryPoints` are supported.
35+
### out
3236

33-
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.
37+
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.
38+
39+
### esbuildOptions
40+
41+
Any custom [esbuild build](https://esbuild.github.io/api/#build-api) options. It defaults to:
42+
43+
```js
44+
{
45+
outdir: out /* = 'build' */, // Unless a outfile is specified
46+
bundle: true,
47+
format: 'esm',
48+
platform: 'node',
49+
target: 'node12',
50+
external: [ /* package.json#dependencies */ ]
51+
}
52+
```
3453

3554
## Environment variables
3655

packages/adapter-node/index.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
declare function plugin(options?: import('esbuild').BuildOptions): import('@sveltejs/kit').Adapter;
1+
declare function plugin(options?: {
2+
out?: string;
3+
esbuildOptions?: import('esbuild').BuildOptions;
4+
}): import('@sveltejs/kit').Adapter;
25

36
export = plugin;

packages/adapter-node/index.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,32 @@ import { fileURLToPath } from 'url';
44
import esbuild from 'esbuild';
55

66
/**
7-
* @param {import('esbuild').BuildOptions} options
7+
* @param {{
8+
* out?: string,
9+
* esbuildOptions?: import('esbuild').BuildOptions
10+
* }} options
811
*/
912
export default function ({
10-
outdir = 'build',
11-
outfile = join(outdir, 'index.js'),
12-
bundle = true,
13-
format = 'esm',
14-
platform = 'node',
15-
target = 'node12',
16-
external = Object.keys(JSON.parse(readFileSync('package.json', 'utf8')).dependencies || {}),
17-
...esbuildOptions
13+
out = 'build',
14+
esbuildOptions: {
15+
outfile,
16+
outdir = typeof outfile === 'undefined' ? out : undefined,
17+
bundle = true,
18+
format = 'esm',
19+
platform = 'node',
20+
target = 'node12',
21+
external = Object.keys(JSON.parse(readFileSync('package.json', 'utf8')).dependencies || {}),
22+
entryPoints = ['.svelte-kit/node/index.js'],
23+
...esbuildOptions
24+
} = {}
1825
} = {}) {
1926
/** @type {import('@sveltejs/kit').Adapter} */
2027
const adapter = {
2128
name: '@sveltejs/adapter-node',
2229

2330
async adapt({ utils }) {
2431
utils.log.minor('Copying assets');
25-
const static_directory = join(outdir, 'assets');
32+
const static_directory = join(out, 'assets');
2633
utils.copy_client_files(static_directory);
2734
utils.copy_static_files(static_directory);
2835

@@ -38,12 +45,12 @@ export default function ({
3845
platform,
3946
target,
4047
external,
41-
entryPoints: ['.svelte-kit/node/index.js']
48+
entryPoints
4249
});
4350

4451
utils.log.minor('Prerendering static pages');
4552
await utils.prerender({
46-
dest: `${outdir}/prerendered`
53+
dest: `${out}/prerendered`
4754
});
4855
}
4956
};

0 commit comments

Comments
 (0)