Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
66 lines (52 loc) · 1.89 KB
/
Copy pathindex.js
File metadata and controls
66 lines (52 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { writeFileSync } from 'fs';
import { join } from 'path';
import { fileURLToPath } from 'url';
import { appResolver } from '@sveltejs/kit/adapter';
import esbuild from 'esbuild';
/**
* @typedef {import('esbuild').BuildOptions} BuildOptions
*/
/** @type {import('.')} **/
export default function (options) {
return {
name: '@sveltejs/adapter-vercel',
async adapt({ utils }) {
const dir = '.vercel_build_output';
utils.rimraf(dir);
const files = fileURLToPath(new URL('./files', import.meta.url));
const dirs = {
static: join(dir, 'static'),
lambda: join(dir, 'functions/node/render')
};
// TODO ideally we'd have something like utils.tmpdir('vercel')
// rather than hardcoding '.svelte-kit/vercel/entry.js', and the
// relative import from that file to output/server/app.js
// would be controlled. at the moment we're exposing
// implementation details that could change
utils.log.minor('Generating serverless function...');
utils.copy(join(files, 'entry.js'), '.svelte-kit/vercel/entry.js');
/** @type {BuildOptions} */
const default_options = {
entryPoints: ['.svelte-kit/vercel/entry.js'],
outfile: join(dirs.lambda, 'index.js'),
bundle: true,
inject: [join(files, 'shims.js')],
plugins: [appResolver()],
platform: 'node'
};
const build_options =
options && options.esbuild ? await options.esbuild(default_options) : default_options;
await esbuild.build(build_options);
writeFileSync(join(dirs.lambda, 'package.json'), JSON.stringify({ type: 'commonjs' }));
utils.log.minor('Prerendering static pages...');
await utils.prerender({
dest: dirs.static
});
utils.log.minor('Copying assets...');
utils.copy_static_files(dirs.static);
utils.copy_client_files(dirs.static);
utils.log.minor('Writing routes...');
utils.copy(join(files, 'routes.json'), join(dir, 'config/routes.json'));
}
};
}