-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
60 lines (51 loc) · 1.48 KB
/
index.js
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
const { copyFileSync, writeFileSync, unlinkSync } = require('fs');
const { join } = require('path');
const esbuild = require('esbuild');
/**
* @param {{
* out?: string;
* }} options
*/
module.exports = function ({ out = 'build' } = {}) {
/** @type {import('@sveltejs/kit').Adapter} */
const adapter = {
name: 'adapter-serverless',
async adapt(builder) {
builder.log.minor('Copying assets');
const static_directory = join(out, 'assets');
builder.copy_client_files(static_directory);
builder.copy_static_files(static_directory);
builder.log.minor('Copying server');
builder.copy_server_files(out);
copyFileSync(`${__dirname}/files/serverless.js`, `${out}/_serverless.js`);
builder.log.minor('Building lambda');
esbuild.buildSync({
entryPoints: [`${out}/_serverless.js`],
outfile: `${out}/serverless.js`,
format: 'cjs',
bundle: true,
platform: 'node',
});
writeFileSync(
`${out}/package.json`,
JSON.stringify(
{
name: 'svelte-serverless',
version: '1.0.0',
main: 'serverless.js',
},
null,
2,
),
);
builder.log.minor('Prerendering static pages');
await builder.prerender({
dest: `${out}/prerendered`,
});
builder.log.minor('Cleanup');
unlinkSync(`${out}/_serverless.js`);
unlinkSync(`${out}/app.js`);
},
};
return adapter;
};