Skip to content

Commit

Permalink
Update Astro and adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
kytta committed Feb 12, 2024
1 parent 7628f8d commit ed4fa3f
Show file tree
Hide file tree
Showing 3 changed files with 715 additions and 951 deletions.
34 changes: 30 additions & 4 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { defineConfig } from "astro/config";
import lightningcss from "vite-plugin-lightningcss";

import cloudflare from "@astrojs/cloudflare";
import deno from "@astrojs/deno";
import netlify from "@astrojs/netlify/functions";
import netlify from "@astrojs/netlify";
import node from "@astrojs/node";
import vercel from "@astrojs/vercel/serverless";

import browserslist from "browserslist";
import lightningcss from "lightningcss";
import { browserslistToTargets } from "lightningcss";

let adapterConfig = {};
if (process.env.VERCEL) {
console.info("Using Vercel (serverless) adapter...");
Expand All @@ -24,7 +27,7 @@ if (process.env.VERCEL) {
}),
};
} else if (process.env.CF_PAGES) {
console.info("Using Cloudflare adapter...");
console.info("Using Cloudflare (Pages) adapter...");
adapterConfig = {
adapter: cloudflare(),
};
Expand All @@ -48,13 +51,36 @@ if (process.env.VERCEL) {
};
}

const lightningCssPlugin = () => {
const targets = browserslistToTargets(browserslist());
return {
name: "vite-plugin-lightningcss",
transform(source, id) {
if (!id.endsWith(".css")) return;

const { code, map } = lightningcss.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: [lightningcss()],
plugins: [lightningCssPlugin()],
},
});
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,27 @@
},
"browserslist": "cover 95%, last 2 versions, Firefox ESR, not dead",
"dependencies": {
"@astrojs/cloudflare": "^7.7.1",
"@astrojs/cloudflare": "^9.0.0",
"@astrojs/deno": "^5.0.1",
"@astrojs/netlify": "^3.1.1",
"@astrojs/node": "^6.1.0",
"@astrojs/vercel": "^5.2.0",
"@astrojs/netlify": "^5.1.1",
"@astrojs/node": "^8.2.0",
"@astrojs/vercel": "^7.3.0",
"@nanostores/persistent": "^0.9.1",
"astro": "^3.6.4",
"astro": "^4.3.6",
"nanostores": "^0.9.5"
},
"devDependencies": {
"@astrojs/check": "^0.4.1",
"@astrojs/check": "^0.5.3",
"@types/node": "^18.17.0",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"browserslist": "^4.22.3",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-astro": "^0.31.4",
"eslint-plugin-unicorn": "^51.0.1",
"husky": "^9.0.10",
"lightningcss": "^1.23.0",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"prettier-plugin-astro": "^0.13.0",
Expand All @@ -59,8 +61,7 @@
"stylelint": "^16.2.1",
"stylelint-config-standard-scss": "^13.0.0",
"svgo": "^3.2.0",
"typescript": "^5.3.3",
"vite-plugin-lightningcss": "^0.0.5"
"typescript": "^5.3.3"
},
"lint-staged": {
"*": "pnpm run fix:prettier",
Expand Down
Loading

0 comments on commit ed4fa3f

Please sign in to comment.