-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
astro.config.ts
84 lines (77 loc) · 2.08 KB
/
astro.config.ts
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* eslint-env node */
/*!
* This file is part of Share₂Fedi
* https://github.com/kytta/share2fedi
*
* SPDX-FileCopyrightText: © 2023 Nikita Karamov <me@kytta.dev>
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { defineConfig } from "astro/config";
import browserslist from "browserslist";
import { browserslistToTargets, transform } from "lightningcss";
let adapterConfig = {};
if (process.env.VERCEL) {
console.info("Using Vercel (serverless) adapter...");
const { default: vercel } = await import("@astrojs/vercel/serverless");
adapterConfig = {
adapter: vercel({
functionPerRoute: true,
}),
};
} else if (process.env.CF_PAGES) {
console.info("Using Cloudflare (Pages) adapter...");
const { default: cloudflare } = await import("@astrojs/cloudflare");
adapterConfig = {
adapter: cloudflare(),
};
} else if (process.env.NETLIFY) {
console.info("Using Netlify (Functions) adapter...");
const { default: netlify } = await import("@astrojs/netlify");
adapterConfig = {
adapter: netlify(),
};
} else if (process.argv.includes("--s2f-use-deno")) {
console.info("Using Deno adapter...");
const { default: deno } = await import("@astrojs/deno");
adapterConfig = {
adapter: deno(),
};
} else {
console.info("Using Node.js adapter...");
console.info("Run with '--s2f-use-deno' flag to use Deno");
const { default: node } = await import("@astrojs/node");
adapterConfig = {
adapter: node({
mode: "standalone",
}),
};
}
const lightningCssPlugin = () => {
const targets = browserslistToTargets(browserslist());
return {
name: "vite-plugin-lightningcss",
transform(source: string, id: string) {
if (!id.endsWith(".css")) return;
const { code, map } = transform({
filename: id,
code: Buffer.from(source),
minify: true,
sourceMap: true,
targets,
});
return {
code: code.toString(),
// eslint-disable-next-line unicorn/no-null
map: map ? map.toString() : null,
};
},
};
};
export default defineConfig({
site: "https://s2f.kytta.dev",
output: "server",
...adapterConfig,
vite: {
plugins: [lightningCssPlugin()],
},
});