2023-08-30 12:02:51 +02:00
|
|
|
/* eslint-env node */
|
2023-09-02 16:17:15 +02:00
|
|
|
/*!
|
|
|
|
* 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
|
|
|
|
*/
|
2023-03-17 21:08:08 +01:00
|
|
|
import { defineConfig } from "astro/config";
|
|
|
|
|
2024-02-12 21:12:27 +01:00
|
|
|
import browserslist from "browserslist";
|
|
|
|
import { browserslistToTargets, transform } from "lightningcss";
|
|
|
|
|
2023-08-30 12:19:28 +02:00
|
|
|
let adapterConfig = {};
|
2023-08-26 15:27:20 +02:00
|
|
|
if (process.env.VERCEL) {
|
|
|
|
console.info("Using Vercel (serverless) adapter...");
|
2024-09-13 11:21:25 +02:00
|
|
|
const { default: vercel } = await import("@astrojs/vercel/serverless");
|
2023-08-30 12:19:28 +02:00
|
|
|
adapterConfig = {
|
2023-09-02 22:15:57 +02:00
|
|
|
adapter: vercel({
|
|
|
|
functionPerRoute: true,
|
|
|
|
}),
|
2023-08-26 15:27:20 +02:00
|
|
|
};
|
|
|
|
} else if (process.env.CF_PAGES) {
|
2024-02-12 21:12:27 +01:00
|
|
|
console.info("Using Cloudflare (Pages) adapter...");
|
2024-09-13 11:21:25 +02:00
|
|
|
const { default: cloudflare } = await import("@astrojs/cloudflare");
|
2023-08-30 12:19:28 +02:00
|
|
|
adapterConfig = {
|
2023-08-26 15:27:20 +02:00
|
|
|
adapter: cloudflare(),
|
|
|
|
};
|
2023-03-17 21:08:08 +01:00
|
|
|
} else if (process.env.NETLIFY) {
|
2023-08-26 15:27:20 +02:00
|
|
|
console.info("Using Netlify (Functions) adapter...");
|
2024-09-13 11:21:25 +02:00
|
|
|
const { default: netlify } = await import("@astrojs/netlify");
|
2023-08-30 12:19:28 +02:00
|
|
|
adapterConfig = {
|
2023-09-02 23:35:04 +02:00
|
|
|
adapter: netlify(),
|
2023-08-26 15:27:20 +02:00
|
|
|
};
|
|
|
|
} else if (process.argv.includes("--s2f-use-deno")) {
|
|
|
|
console.info("Using Deno adapter...");
|
2024-09-13 11:21:25 +02:00
|
|
|
const { default: deno } = await import("@astrojs/deno");
|
2023-08-30 12:19:28 +02:00
|
|
|
adapterConfig = {
|
2023-08-26 15:27:20 +02:00
|
|
|
adapter: deno(),
|
|
|
|
};
|
2023-03-17 21:08:08 +01:00
|
|
|
} else {
|
2023-08-26 15:27:20 +02:00
|
|
|
console.info("Using Node.js adapter...");
|
|
|
|
console.info("Run with '--s2f-use-deno' flag to use Deno");
|
2024-09-13 11:21:25 +02:00
|
|
|
const { default: node } = await import("@astrojs/node");
|
2023-08-30 12:19:28 +02:00
|
|
|
adapterConfig = {
|
2023-08-26 15:27:20 +02:00
|
|
|
adapter: node({
|
|
|
|
mode: "standalone",
|
|
|
|
}),
|
|
|
|
};
|
2023-03-17 21:08:08 +01:00
|
|
|
}
|
|
|
|
|
2024-02-12 21:12:27 +01:00
|
|
|
const lightningCssPlugin = () => {
|
|
|
|
const targets = browserslistToTargets(browserslist());
|
|
|
|
return {
|
|
|
|
name: "vite-plugin-lightningcss",
|
2024-02-25 01:13:26 +01:00
|
|
|
transform(source: string, id: string) {
|
2024-02-12 21:12:27 +01:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-03-17 21:08:08 +01:00
|
|
|
export default defineConfig({
|
|
|
|
site: "https://s2f.kytta.dev",
|
2023-08-30 12:19:28 +02:00
|
|
|
|
|
|
|
output: "server",
|
|
|
|
...adapterConfig,
|
|
|
|
|
2023-08-26 15:37:02 +02:00
|
|
|
vite: {
|
2024-02-12 21:12:27 +01:00
|
|
|
plugins: [lightningCssPlugin()],
|
2023-08-26 15:37:02 +02:00
|
|
|
},
|
2023-03-17 21:08:08 +01:00
|
|
|
});
|