refactor(nuxt): add cache, treeshaking and sourcemap capabilities to nuxt config

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2023-10-11 16:53:33 -04:00
parent b1c94ab0ae
commit 1b75c199a4
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

View File

@ -4,6 +4,17 @@ import { defineNuxtModule } from "@nuxt/kit";
// import speedkitHydrate from "nuxt-speedkit/dist/runtime/hydrate.mjs"; // import speedkitHydrate from "nuxt-speedkit/dist/runtime/hydrate.mjs";
export type SessionData = IUser; export type SessionData = IUser;
const cac = {
isr: true,
headersOnly: true,
cache: {
headersOnly: true,
// integrity: "",
// varies: ["Content-Length"],
maxAge: 60,
},
swr: false,
};
const ct = const ct =
<T>() => <T>() =>
<U extends T>(u: U) => <U extends T>(u: U) =>
@ -12,7 +23,7 @@ export default defineNuxtConfig({
experimental: { experimental: {
watcher: "chokidar-granular", watcher: "chokidar-granular",
// noScripts: true, // noScripts: true,
treeshakeClientOnly: false, treeshakeClientOnly: true,
}, },
devtools: { enabled: false }, devtools: { enabled: false },
modules: [ modules: [
@ -21,23 +32,18 @@ export default defineNuxtConfig({
"@sidebase/nuxt-auth", "@sidebase/nuxt-auth",
"@pinia/nuxt", "@pinia/nuxt",
"@vueuse/nuxt", "@vueuse/nuxt",
// defineNuxtModule({ "nuxt-speedkit",
// async setup(options, nuxt) {
// nuxt.hook("components:extend", (components) => {
// // console.log(components);
// // components = components.map((a) => {
// // return speedkitHydrate(() => import(a.filePath));
// // });
// });
// },
// }),
// "nuxt-speedkit",
], ],
// speedkit: { speedkit: {
// disableNuxtFontaine: true, disableNuxtFontaine: true,
// }, lazyOffset: {
component: "0%",
asset: "0%",
},
},
css: ["~/public/fonts.css", "~/public/css/all.css"], css: ["~/public/fonts.css", "~/public/css/all.css"],
auth: { auth: {
baseURL: "/api/auth",
provider: { provider: {
type: "local", type: "local",
pages: { pages: {
@ -47,27 +53,51 @@ export default defineNuxtConfig({
signInResponseTokenPointer: "/token", signInResponseTokenPointer: "/token",
type: "Bearer", type: "Bearer",
headerName: "Authorization", headerName: "Authorization",
maxAgeInSeconds: 168 * 24 * 60 * 60, maxAgeInSeconds: 14 * 24 * 60 * 60,
sameSiteAttribute: "lax", // sameSiteAttribute: ,
}, },
sessionDataType: {} as { [Property in keyof IUser]: string }, sessionDataType: {} as { [Property in keyof IUser]: string },
endpoints: { endpoints: {
signUp: { path: "/register", method: "post" }, signUp: { path: "/register", method: "post" },
signOut: { path: "/logout", method: "post" },
getSession: {
path: "/session",
method: "get",
},
}, },
}, },
globalAppMiddleware: { globalAppMiddleware: false,
isEnabled: false,
//@ts-ignore
session: {
enableRefreshPeriodically: 60 * 60 * 2 * 1000,
enableRefreshOnWindowFocus: false,
}, },
}, },
nitro: { nitro: {
esbuild: { esbuild: {
options: { options: {
minify: true, 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: { // routeRules: {
// "/**": { // "/**": {
// cache: { // cache: {
@ -78,6 +108,10 @@ export default defineNuxtConfig({
// }, // },
// }, // },
// ssr: false, // ssr: false,
sourcemap: {
server: true,
client: true,
},
runtimeConfig: { runtimeConfig: {
captcha: { captcha: {
secret: process.env.CAPTCHASECRET, secret: process.env.CAPTCHASECRET,
@ -93,6 +127,11 @@ export default defineNuxtConfig({
recaptcha: { recaptcha: {
v2SiteKey: process.env.CAPTCHAKEY, v2SiteKey: process.env.CAPTCHAKEY,
}, },
auth: {
computed: {
origin: "127.0.0.1",
},
},
// apiBase: "/api" // apiBase: "/api"
}, },
nodebb: { nodebb: {