-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvelte.config.js
76 lines (67 loc) · 1.94 KB
/
svelte.config.js
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
import preprocess from "svelte-preprocess"
import adapterAuto from "@sveltejs/adapter-auto"
import adapterStatic from "@sveltejs/adapter-static"
import { vitePreprocess } from "@sveltejs/kit/vite"
import * as fs from "fs/promises"
import * as childprocess from "child_process"
// isCloud is true if the app is being deployed to a cloud provider.
// Keep this up to date with adapterAuto's list of cloud providers:
// https://github.com/sveltejs/kit/blob/master/packages/adapter-auto/adapters.js
const isCloud =
!!process.env.VERCEL ||
!!process.env.NETLIFY ||
!!process.env.CF_PAGES ||
process.env.GITHUB_ACTION_REPOSITORY === "Azure/static-web-apps-deploy"
const preHooks = []
async function injectHead(outdir, head) {
await editFile(`${outdir}/index.html`, (html) => {
return html.replace(/%sveltekit.head%/, head + "\n%sveltekit.head%")
})
}
const postHooks = [
async (outdir) => {
childprocess.spawnSync("prettier", ["--write", `${outdir}/index.html`], {
stdio: "inherit",
})
},
]
async function editFile(path, apply) {
const file = await fs.readFile(path, "utf-8")
const edited = await apply(file)
await fs.writeFile(path, edited)
}
const staticOutDir = "build"
const staticAdapter = adapterStatic({
pages: staticOutDir,
precompress: true,
fallback: "index.html",
strict: true,
})
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: [
vitePreprocess(),
preprocess({
postcss: true,
}),
],
kit: {
adapter: isCloud
? adapterAuto()
: {
name: "adapter-static-but-actually-works",
async adapt(builder) {
await Promise.all(preHooks.map((hook) => hook(staticOutDir)))
await staticAdapter.adapt(builder)
await Promise.all(postHooks.map((hook) => hook(staticOutDir)))
},
},
alias: {
"#": "./src",
},
output: {
preloadStrategy: "preload-mjs",
},
},
}
export default config