From 1b75c199a41354162961881053f48f758d6e5355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Wed, 11 Oct 2023 16:53:33 -0400 Subject: [PATCH] refactor(nuxt): add cache, treeshaking and sourcemap capabilities to nuxt config --- nuxt.config.ts | 81 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 21 deletions(-) diff --git a/nuxt.config.ts b/nuxt.config.ts index 365854a..8084fa9 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -4,6 +4,17 @@ import { defineNuxtModule } from "@nuxt/kit"; // import speedkitHydrate from "nuxt-speedkit/dist/runtime/hydrate.mjs"; export type SessionData = IUser; +const cac = { + isr: true, + headersOnly: true, + cache: { + headersOnly: true, + // integrity: "", + // varies: ["Content-Length"], + maxAge: 60, + }, + swr: false, +}; const ct = () => (u: U) => @@ -12,7 +23,7 @@ export default defineNuxtConfig({ experimental: { watcher: "chokidar-granular", // noScripts: true, - treeshakeClientOnly: false, + treeshakeClientOnly: true, }, devtools: { enabled: false }, modules: [ @@ -21,23 +32,18 @@ export default defineNuxtConfig({ "@sidebase/nuxt-auth", "@pinia/nuxt", "@vueuse/nuxt", - // defineNuxtModule({ - // async setup(options, nuxt) { - // nuxt.hook("components:extend", (components) => { - // // console.log(components); - // // components = components.map((a) => { - // // return speedkitHydrate(() => import(a.filePath)); - // // }); - // }); - // }, - // }), - // "nuxt-speedkit", + "nuxt-speedkit", ], - // speedkit: { - // disableNuxtFontaine: true, - // }, + speedkit: { + disableNuxtFontaine: true, + lazyOffset: { + component: "0%", + asset: "0%", + }, + }, css: ["~/public/fonts.css", "~/public/css/all.css"], auth: { + baseURL: "/api/auth", provider: { type: "local", pages: { @@ -47,27 +53,51 @@ export default defineNuxtConfig({ signInResponseTokenPointer: "/token", type: "Bearer", headerName: "Authorization", - maxAgeInSeconds: 168 * 24 * 60 * 60, - sameSiteAttribute: "lax", + maxAgeInSeconds: 14 * 24 * 60 * 60, + // sameSiteAttribute: , }, sessionDataType: {} as { [Property in keyof IUser]: string }, endpoints: { signUp: { path: "/register", method: "post" }, + signOut: { path: "/logout", method: "post" }, + getSession: { + path: "/session", + method: "get", + }, }, }, - globalAppMiddleware: { - isEnabled: false, + globalAppMiddleware: false, + + //@ts-ignore + session: { + enableRefreshPeriodically: 60 * 60 * 2 * 1000, + enableRefreshOnWindowFocus: false, }, }, nitro: { esbuild: { options: { minify: true, - // sourceMap: false, + sourceMap: "inline", }, }, + preset: "node", + }, + routeRules: { + "/": cac, + "/api/**": { cors: true }, + "/bands/**": cac, + "/authors": cac, + "/story/**": { + swr: true, + isr: true, + cache: { + maxAge: 1800, + }, + }, + // "/authors": { swr: 0 }, + // "/bands": { swr: 0 }, }, - // routeRules: { // "/**": { // cache: { @@ -78,6 +108,10 @@ export default defineNuxtConfig({ // }, // }, // ssr: false, + sourcemap: { + server: true, + client: true, + }, runtimeConfig: { captcha: { secret: process.env.CAPTCHASECRET, @@ -93,6 +127,11 @@ export default defineNuxtConfig({ recaptcha: { v2SiteKey: process.env.CAPTCHAKEY, }, + auth: { + computed: { + origin: "127.0.0.1", + }, + }, // apiBase: "/api" }, nodebb: {