Skip to content

Commit

Permalink
feat: use undici, build to node by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ddiu8081 committed Mar 4, 2023
1 parent 6f6d524 commit dd7dd62
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 163 deletions.
25 changes: 23 additions & 2 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import { defineConfig } from 'astro/config'
import vercel from '@astrojs/vercel/edge'
import unocss from 'unocss/astro'
import { presetUno } from 'unocss'
import presetAttributify from '@unocss/preset-attributify'
import presetTypography from '@unocss/preset-typography'
import solidJs from '@astrojs/solid-js'
import vercelDisableBlocks from './plugins/vercelDisableBlocks'

import node from '@astrojs/node'
import vercel from '@astrojs/vercel/edge'

const envAdapter = () => {
if (process.env.OUTPUT == 'vercel') {
return vercel({
excludeFiles: ['./src/pages/api/generate.ts']
})
} else {
return node({
mode: 'standalone'
})
}
}

// https://astro.build/config
export default defineConfig({
Expand All @@ -19,5 +34,11 @@ export default defineConfig({
solidJs()
],
output: 'server',
adapter: vercel()
adapter: envAdapter(),
vite: {
plugins: [
// conditionalCompile(),
process.env.OUTPUT == 'vercel' && vercelDisableBlocks(),
]
},
});
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"build:vercel": "OUTPUT=vercel astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@astrojs/node": "^5.0.4",
"@astrojs/solid-js": "^2.0.2",
"@astrojs/vercel": "^3.1.3",
"@unocss/reset": "^0.50.1",
"astro": "^2.0.15",
"eventsource-parser": "^0.1.0",
"highlight.js": "^11.7.0",
"https-proxy-agent": "^5.0.1",
"katex": "^0.6.0",
"markdown-it": "^13.0.1",
"markdown-it-highlightjs": "^4.0.1",
"markdown-it-katex": "^2.0.3",
"node-fetch": "^3.3.0",
"solid-js": "^1.6.11"
"solid-js": "^1.6.11",
"undici": "^5.20.0"
},
"devDependencies": {
"@types/markdown-it": "^12.2.3",
"@types/node-fetch": "^2.6.2",
"@unocss/preset-attributify": "^0.50.1",
"@unocss/preset-typography": "^0.50.3",
"punycode": "^2.3.0",
"stream": "^0.0.2",
"unocss": "^0.50.1"
}
}
16 changes: 16 additions & 0 deletions plugins/vercelDisableBlocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default function plugin() {
const transform = (code: string, id: string) => {
if (id.includes('pages/api/generate.ts')) {
return {
code: code.replace(/^.*?#vercel-disable-blocks([\s\S]+?)#vercel-end.*?$/gm, ''),
map: null
}
}
}

return {
name: 'vercel-disable-blocks',
enforce: 'pre',
transform,
}
}
Loading

0 comments on commit dd7dd62

Please sign in to comment.