From b2707591ad7eb7634dca4ac42d8eda2ca8f22e7b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 12 May 2022 15:17:15 -0400 Subject: [PATCH] append function redirects after copying existing redirects - fixes #4722 --- .changeset/ninety-books-jam.md | 5 +++++ packages/adapter-netlify/index.js | 26 +++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 .changeset/ninety-books-jam.md diff --git a/.changeset/ninety-books-jam.md b/.changeset/ninety-books-jam.md new file mode 100644 index 000000000000..36775af4d586 --- /dev/null +++ b/.changeset/ninety-books-jam.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-netlify': patch +--- + +Copy existing \_redirects file before appending function redirects diff --git a/packages/adapter-netlify/index.js b/packages/adapter-netlify/index.js index 917dabe00e65..d021ed4799d5 100644 --- a/packages/adapter-netlify/index.js +++ b/packages/adapter-netlify/index.js @@ -54,6 +54,19 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) { builder.log.minor(`Publishing to "${publish}"`); + builder.log.minor('Copying assets...'); + builder.writeStatic(publish); + builder.writeClient(publish); + builder.writePrerendered(publish); + + builder.log.minor('Writing custom headers...'); + const headers_file = join(publish, '_headers'); + builder.copy('_headers', headers_file); + appendFileSync( + headers_file, + `\n\n/${builder.config.kit.appDir}/*\n cache-control: public\n cache-control: immutable\n cache-control: max-age=31536000\n` + ); + // for esbuild, use ESM // for zip-it-and-ship-it, use CJS until https://github.com/netlify/zip-it-and-ship-it/issues/750 const esm = netlify_config?.functions?.node_bundler === 'esbuild'; @@ -67,19 +80,6 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) { } else { await generate_lambda_functions({ builder, esm, split, publish }); } - - builder.log.minor('Copying assets...'); - builder.writeStatic(publish); - builder.writeClient(publish); - builder.writePrerendered(publish); - - builder.log.minor('Writing custom headers...'); - const headers_file = join(publish, '_headers'); - builder.copy('_headers', headers_file); - appendFileSync( - headers_file, - `\n\n/${builder.config.kit.appDir}/*\n cache-control: public\n cache-control: immutable\n cache-control: max-age=31536000\n` - ); } }; }