-
Notifications
You must be signed in to change notification settings - Fork 1
/
nitro.config.ts
98 lines (85 loc) · 3.18 KB
/
nitro.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { writeFile } from 'node:fs/promises'
import { makeDirectory } from 'make-dir'
import { resolve } from 'pathe'
import type { AcceptedPlugin } from 'postcss'
import { isDevelopment, isProduction } from 'std-env'
import { env, process, provider } from 'std-env'
import type { AppConfig } from '~/types/config'
const isCloudflarePages = provider === 'cloudflare_pages'
const baseURL = isCloudflarePages ? env.CF_PAGES_URL : 'http://localhost:3000'
const plausibleURL = env.PLAUSIBLE_BASE_URL
// Create a reusable function for Tailwind compilation
const compileTailwind = async () => {
const { default: postcss } = await import('postcss')
const { default: tailwindcss } = await import('tailwindcss')
const { default: autoprefixer } = await import('autoprefixer')
const { default: cssnano } = await import('cssnano')
const shouldMinifyCss = isCloudflarePages || !process.dev
const postCssPlugins: AcceptedPlugin[] = [
tailwindcss(),
autoprefixer(),
shouldMinifyCss && cssnano({ preset: 'default' }),
]
const result = await postcss(postCssPlugins.filter(Boolean)).process(
'@tailwind base; @tailwind components; @tailwind utilities;',
{ from: undefined }
)
// Create assets direcctory for Tailwind CSS output file
await makeDirectory(resolve('.output/assets'), { mode: 0o755 })
await makeDirectory(resolve('public/assets'), { mode: 0o755 })
// Write the compiled CSS to the public directory
await writeFile(resolve('public/assets/styles.css'), result.css)
// This is required for Cloudflare Pages to serve the CSS file
await writeFile(resolve('.output/assets/styles.css'), result.css)
}
/* https://nitro.unjs.io/config */
export default defineNitroConfig({
compatibilityDate: '2024-11-08',
srcDir: 'server',
preset: 'cloudflare-pages',
minify: isProduction,
sourceMap: isDevelopment,
errorHandler: '~/error',
output: { dir: resolve('.output') },
publicAssets: [{ dir: resolve('public') }],
serverAssets: [{ baseName: 'views', dir: resolve('server/views') }],
prerender: {
autoSubfolderIndex: true,
crawlLinks: true,
failOnError: true,
routes: ['/', '/password', '/privacy', '/terms', '/stats'],
},
routeRules: {
'/author': {
redirect: 'https://ripandis.com/?utm_source=authweb',
prerender: false,
},
'/github': {
redirect: 'https://github.com/riipandi/authweb',
prerender: false,
},
'/x': {
redirect: 'https://x.com/intent/follow?screen_name=riipandi',
prerender: false,
},
'/js/embed.host.js': { proxy: `${plausibleURL}/js/embed.host.js` },
'/js/script.js': { proxy: `${plausibleURL}/js/script.js` },
'/api/event': { proxy: `${plausibleURL}/api/event` },
},
hooks: {
'rollup:before': async () => {
await compileTailwind()
},
'dev:reload': async () => {
await compileTailwind()
},
},
appConfig: {
baseURL,
title: 'AuthWeb',
description:
'Free online TOTP/HOTP generator and password manager. Create secure one-time passwords and 2FA tokens directly in your browser. Open source, privacy-focused, and no registration required.',
author: 'Aris Ripandi',
siteDomain: env.PLAUSIBLE_DATA_DOMAIN,
} as AppConfig,
})