chore: netlify (#46)

vercel will explod
This commit is contained in:
Ax333l 2022-12-21 21:37:35 +01:00 committed by GitHub
parent 8f031178b3
commit 8d73663ae3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 85 deletions

3
netlify.toml Normal file
View File

@ -0,0 +1,3 @@
[build]
publish = "public/"
command = "npm run build"

View File

@ -1,82 +0,0 @@
import fs from 'fs';
// This code was stolen from https://github.com/sveltejs/kit/blob/master/packages/adapter-static/platforms.js
// sveltekit does things like this instead of actually just using ts for some reason.
/** @param {import('@sveltejs/kit').Builder} builder */
function vercel_routes(builder) {
/** @type {any[]} */
const routes = [
{
src: `/${builder.config.kit.appDir}/immutable/.+`,
headers: {
'cache-control': 'public, immutable, max-age=31536000'
}
}
];
// explicit redirects
for (const [src, redirect] of builder.prerendered.redirects) {
routes.push({
src,
headers: {
Location: redirect.location
},
status: redirect.status
});
}
// prerendered pages
for (const [src, page] of builder.prerendered.pages) {
routes.push({
src,
dest: `__revanced/prerendered/${page.file}`
});
}
// implicit redirects (trailing slashes)
for (const [src] of builder.prerendered.pages) {
if (src !== '/') {
routes.push({
src: src.endsWith('/') ? src.slice(0, -1) : src + '/',
headers: {
location: src
},
status: 308
});
}
}
routes.push({
handle: 'filesystem'
});
return routes;
}
export function wrap(adapter, opts) {
if (!process.env.VERCEL) {
// we don't have to bother :)
return adapter(opts);
}
opts.pages = `.vercel/output/static/__revanced/prerendered`
opts.assets = '.vercel/output/static';
adapter = adapter(opts);
const adapt_fn = adapter.adapt;
adapter.adapt = async (builder) => {
const result = await adapt_fn(builder);
fs.writeFileSync(
'.vercel/output/config.json',
JSON.stringify({
version: 3,
routes: vercel_routes(builder)
})
);
return result;
}
return adapter;
}

View File

@ -1,8 +1,6 @@
import adapter from '@sveltejs/adapter-static';
import preprocess from 'svelte-preprocess';
import { wrap } from './src/_vercel-moment.js';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
@ -12,7 +10,7 @@ const config = {
kit: {
// adapter-static has vercel detection, but that does not let you set a custom 404 page easily.
// Instead, we have to use a wrapper that generates a vercel config if on vercel...
adapter: wrap(adapter, {
adapter: adapter({
pages: "public",
fallback: "404.html"
}),