Skip to content

Commit

Permalink
fix: use esbuildOptions parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
sastan committed Jun 16, 2021
1 parent ed6b445 commit dfae928
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
37 changes: 28 additions & 9 deletions packages/adapter-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,42 @@ 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 */
]
}
})
}
};
```

## 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

Expand Down
5 changes: 4 additions & 1 deletion packages/adapter-node/index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
31 changes: 19 additions & 12 deletions packages/adapter-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@ import { fileURLToPath } from 'url';
import esbuild from 'esbuild';

/**
* @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 = {
name: '@sveltejs/adapter-node',

async adapt({ utils }) {
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);

Expand All @@ -38,12 +45,12 @@ export default function ({
platform,
target,
external,
entryPoints: ['.svelte-kit/node/index.js']
entryPoints
});

utils.log.minor('Prerendering static pages');
await utils.prerender({
dest: `${outdir}/prerendered`
dest: `${out}/prerendered`
});
}
};
Expand Down

0 comments on commit dfae928

Please sign in to comment.