Skip to content

Commit

Permalink
tinkering
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Apr 18, 2021
1 parent 40cc5b7 commit 997b48e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
28 changes: 16 additions & 12 deletions packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,36 @@ module.exports = function () {

async adapt(utils) {
const vercel_output_directory = resolve('.vercel_build_output');
utils.rimraf(vercel_output_directory);

const config_directory = join(vercel_output_directory, 'config');
const static_directory = join(vercel_output_directory, 'static');
const lambda_directory = join(vercel_output_directory, 'functions', 'node', 'render');
const server_directory = join(lambda_directory, 'server');

utils.copy(join(__dirname, 'src/entry.js'), '.svelte/vercel/entry.js');

const esbuild = (await import('esbuild')).default;

await esbuild.build({
entryPoints: ['.svelte/vercel/entry.js'],
outfile: join(lambda_directory, 'index.js'),
bundle: true,
platform: 'node'
});

writeFileSync(join(lambda_directory, 'package.json'), JSON.stringify({ type: 'commonjs' }));

utils.log.minor('Writing client application...');
utils.copy_static_files(static_directory);
utils.copy_client_files(static_directory);

utils.log.minor('Building lambda...');
utils.copy_server_files(server_directory);
renameSync(join(server_directory, 'app.js'), join(server_directory, 'app.mjs'));

utils.copy(join(__dirname, 'files'), lambda_directory);

utils.log.minor('Prerendering static pages...');
await utils.prerender({
dest: static_directory
});

utils.log.minor('Writing routes...');
try {
mkdirSync(config_directory);
} catch {
// directory already exists
}
utils.mkdirp(config_directory);
writeFileSync(
join(config_directory, 'routes.json'),
JSON.stringify([
Expand Down
1 change: 1 addition & 0 deletions packages/adapter-vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"devDependencies": {
"@sveltejs/kit": "workspace:*",
"esbuild": "^0.11.12",
"rollup": "^2.41.1",
"sirv": "^1.0.11",
"typescript": "^4.2.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-vercel/src/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ globalThis.Headers = Headers;
export default async (req, res) => {
const { pathname, searchParams } = new URL(req.url || '', 'http://localhost');

const { render } = await import('./server/app.mjs');
const { render } = await import('../output/server/app.js');

const rendered = await render({
method: req.method,
Expand Down
8 changes: 1 addition & 7 deletions packages/create-svelte/templates/default/svelte.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ const config = {

kit: {
// hydrate the <div id="svelte"> element in src/app.html
target: '#svelte',

vite: {
ssr: {
noExternal: Object.keys(pkg.dependencies || {})
}
}
target: '#svelte'
}
};

Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 997b48e

Please sign in to comment.