pesde/website/vite.config.ts

90 lines
2.7 KiB
TypeScript
Raw Normal View History

feat: website * feat(website): init * feat(website): home page * feat(website): make page more responsive * feat(website): layout * feat(website): package page * feat(website): update PackageResponse type * feat(website): display package readme * feat(website): use new /latest/any endpoint * feat(website): make website lg instead of xl * fix(website): use NodeJS.Timeout * feat(website): versions page * feat(website): add latest version indicator * feat(website): add target select menu * feat(website): indicate current version * feat(website): add package metadata * feat(website): add hamburger * fix(website): header responsiveness * feat(website): better package layout * feat(website): display authors on package page * fix(website): only display relative dates on client * feat(docs): init docs site * chore(website): read .env from project root * feat(website): add gemoji support * fix(website): overflow on code blocks * chore(docs): read .env from project root * feat(docs): config changes * fix: authors not displaying * fix(website): use fallback language * refactor(website): use predefined target names * refactor(website): change Github to GitHub * chore: remove starter readmes * chore(docs): remove .vscode * chore(docs): remove unused assets folder * fix(website): fix missing datetime attribute * feat(website): switch to universal loaders * feat(docs): search * fix(website): type errors * fix(website): use provided fetch instead of global * feat(website): remove isr * chore(website): add .env.example * feat(website): add icons and metadata * chore(website): add debug logs * chore(website): remove shiki temporarily * fix(website): rehype shiki lazy load * fix(website): use custom highlighter * fix(website): move highlighter creation into load * docs: write docs * feat(website): add og image * feat(website): fix accessibility issues * fix(website): no target selector on mobile * fix(website): close dialog on navigation * fix(website): logo is not a link in hamburger menu * feat(website): dependencies tab * fix(website): use correct dependency target * fix(website): navigation links * feat(website): support wally dependencies * feat(website): metadata + case insensitivity * fix(website): manually implement groupBy `Object.groupBy` isn't supported on Vercel right now. * fix(website): code block with an unknown language * docs(policies): explain & cover more cases * docs: update cli reference * docs: add self hosting registries guide * docs: update README * docs: add more configs to registry guide * fix: favicon and logomark * feat(website): package documentation * fix(website): missing $derive for toc * docs: change SENTRY_URL to SENTRY_DSN * chore(website): remove unused file * chore: remove favicon.zip * fix(website): strip wally# prefix * chore: add changelog entry --------- Co-authored-by: daimond113 <72147841+daimond113@users.noreply.github.com>
2024-10-29 19:06:00 +00:00
import { sveltekit } from "@sveltejs/kit/vite"
2024-11-30 21:22:14 +00:00
import { readFile } from "node:fs/promises"
import path from "node:path"
import { defineConfig, type Plugin, type ResolvedConfig } from "vite"
feat: website * feat(website): init * feat(website): home page * feat(website): make page more responsive * feat(website): layout * feat(website): package page * feat(website): update PackageResponse type * feat(website): display package readme * feat(website): use new /latest/any endpoint * feat(website): make website lg instead of xl * fix(website): use NodeJS.Timeout * feat(website): versions page * feat(website): add latest version indicator * feat(website): add target select menu * feat(website): indicate current version * feat(website): add package metadata * feat(website): add hamburger * fix(website): header responsiveness * feat(website): better package layout * feat(website): display authors on package page * fix(website): only display relative dates on client * feat(docs): init docs site * chore(website): read .env from project root * feat(website): add gemoji support * fix(website): overflow on code blocks * chore(docs): read .env from project root * feat(docs): config changes * fix: authors not displaying * fix(website): use fallback language * refactor(website): use predefined target names * refactor(website): change Github to GitHub * chore: remove starter readmes * chore(docs): remove .vscode * chore(docs): remove unused assets folder * fix(website): fix missing datetime attribute * feat(website): switch to universal loaders * feat(docs): search * fix(website): type errors * fix(website): use provided fetch instead of global * feat(website): remove isr * chore(website): add .env.example * feat(website): add icons and metadata * chore(website): add debug logs * chore(website): remove shiki temporarily * fix(website): rehype shiki lazy load * fix(website): use custom highlighter * fix(website): move highlighter creation into load * docs: write docs * feat(website): add og image * feat(website): fix accessibility issues * fix(website): no target selector on mobile * fix(website): close dialog on navigation * fix(website): logo is not a link in hamburger menu * feat(website): dependencies tab * fix(website): use correct dependency target * fix(website): navigation links * feat(website): support wally dependencies * feat(website): metadata + case insensitivity * fix(website): manually implement groupBy `Object.groupBy` isn't supported on Vercel right now. * fix(website): code block with an unknown language * docs(policies): explain & cover more cases * docs: update cli reference * docs: add self hosting registries guide * docs: update README * docs: add more configs to registry guide * fix: favicon and logomark * feat(website): package documentation * fix(website): missing $derive for toc * docs: change SENTRY_URL to SENTRY_DSN * chore(website): remove unused file * chore: remove favicon.zip * fix(website): strip wally# prefix * chore: add changelog entry --------- Co-authored-by: daimond113 <72147841+daimond113@users.noreply.github.com>
2024-10-29 19:06:00 +00:00
export default defineConfig({
2024-11-30 21:22:14 +00:00
plugins: [sveltekit(), cloudflareWasmImport()],
feat: website * feat(website): init * feat(website): home page * feat(website): make page more responsive * feat(website): layout * feat(website): package page * feat(website): update PackageResponse type * feat(website): display package readme * feat(website): use new /latest/any endpoint * feat(website): make website lg instead of xl * fix(website): use NodeJS.Timeout * feat(website): versions page * feat(website): add latest version indicator * feat(website): add target select menu * feat(website): indicate current version * feat(website): add package metadata * feat(website): add hamburger * fix(website): header responsiveness * feat(website): better package layout * feat(website): display authors on package page * fix(website): only display relative dates on client * feat(docs): init docs site * chore(website): read .env from project root * feat(website): add gemoji support * fix(website): overflow on code blocks * chore(docs): read .env from project root * feat(docs): config changes * fix: authors not displaying * fix(website): use fallback language * refactor(website): use predefined target names * refactor(website): change Github to GitHub * chore: remove starter readmes * chore(docs): remove .vscode * chore(docs): remove unused assets folder * fix(website): fix missing datetime attribute * feat(website): switch to universal loaders * feat(docs): search * fix(website): type errors * fix(website): use provided fetch instead of global * feat(website): remove isr * chore(website): add .env.example * feat(website): add icons and metadata * chore(website): add debug logs * chore(website): remove shiki temporarily * fix(website): rehype shiki lazy load * fix(website): use custom highlighter * fix(website): move highlighter creation into load * docs: write docs * feat(website): add og image * feat(website): fix accessibility issues * fix(website): no target selector on mobile * fix(website): close dialog on navigation * fix(website): logo is not a link in hamburger menu * feat(website): dependencies tab * fix(website): use correct dependency target * fix(website): navigation links * feat(website): support wally dependencies * feat(website): metadata + case insensitivity * fix(website): manually implement groupBy `Object.groupBy` isn't supported on Vercel right now. * fix(website): code block with an unknown language * docs(policies): explain & cover more cases * docs: update cli reference * docs: add self hosting registries guide * docs: update README * docs: add more configs to registry guide * fix: favicon and logomark * feat(website): package documentation * fix(website): missing $derive for toc * docs: change SENTRY_URL to SENTRY_DSN * chore(website): remove unused file * chore: remove favicon.zip * fix(website): strip wally# prefix * chore: add changelog entry --------- Co-authored-by: daimond113 <72147841+daimond113@users.noreply.github.com>
2024-10-29 19:06:00 +00:00
})
2024-11-30 21:22:14 +00:00
// This plugin allows us to import WebAssembly modules and have them work in
// both the browser, Node.js, and Cloudflare Workers.
function cloudflareWasmImport(): Plugin {
const wasmPostfix = ".wasm"
const importMetaPrefix = "___WASM_IMPORT_PATH___"
let config: ResolvedConfig
return {
name: "cloudflare-wasm-import",
configResolved(resolvedConfig) {
config = resolvedConfig
},
async load(id) {
if (!id.endsWith(wasmPostfix)) return
if (config.command === "serve") {
// Running dev server
// We generate a module that on the browser will fetch the WASM file
// (through a Vite `?url` import), and on the server will read the file
// from the file system.
return `
import WASM_URL from ${JSON.stringify(`${id}?url`)}
let promise
export default function() {
if (import.meta.env.SSR) {
return promise ?? (promise = import("node:fs/promises")
.then(({ readFile }) => readFile(${JSON.stringify(id)})))
} else {
return promise ?? (promise = fetch(WASM_URL).then(r => r.arrayBuffer()))
}
}
`
}
// When building, we emit the WASM file as an asset and generate a module
// that will fetch the asset in the browser, import the WASM file when in
// a Cloudflare Worker, and read the file from the file system when in
// Node.js.
const wasmSource = await readFile(id)
const refId = this.emitFile({
type: "asset",
name: path.basename(id),
source: wasmSource,
})
return `
import WASM_URL from ${JSON.stringify(`${id}?url`)}
let promise
export default function() {
if (import.meta.env.SSR) {
if (typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers") {
return promise ?? (promise = import(import.meta.${importMetaPrefix}${refId}))
} else {
return promise ?? (promise = import(\`\${"node:fs/promises"}\`)
.then(({ readFile }) => readFile(new URL(import.meta.ROLLUP_FILE_URL_${refId}))))
}
} else {
return promise ?? (promise = fetch(WASM_URL).then(r => r.arrayBuffer()))
}
}
`
},
resolveImportMeta(property, { chunkId }) {
if (!property?.startsWith(importMetaPrefix)) return
const refId = property.slice(importMetaPrefix.length)
const fileName = this.getFileName(refId)
const relativePath = path.relative(path.dirname(chunkId), fileName)
return JSON.stringify(relativePath)
},
}
}