adapter migrate from vercel to node

This commit is contained in:
MuslemRahimi 2024-09-19 14:36:02 +02:00
parent a825f2a7a0
commit c7cd229cae
6 changed files with 727 additions and 831 deletions

861
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,7 @@
"@internationalized/date": "^3.5.5", "@internationalized/date": "^3.5.5",
"@playwright/test": "^1.43.1", "@playwright/test": "^1.43.1",
"@rollup/plugin-dynamic-import-vars": "^2.1.2", "@rollup/plugin-dynamic-import-vars": "^2.1.2",
"@sveltejs/adapter-vercel": "^5.3.0", "@sveltejs/adapter-node": "^5.2.3",
"@sveltejs/kit": "^2.5.15", "@sveltejs/kit": "^2.5.15",
"@sveltejs/vite-plugin-svelte": "^3.1.0", "@sveltejs/vite-plugin-svelte": "^3.1.0",
"@types/gtag.js": "^0.0.19", "@types/gtag.js": "^0.0.19",

View File

@ -1,30 +1,38 @@
import PocketBase from "pocketbase"; import PocketBase from "pocketbase";
import { serializeNonPOJOs } from "$lib/utils"; import { serializeNonPOJOs } from "$lib/utils";
const usRegion = new Set(["cle1", "iad1", "pdx1", "sfo1"]);
export const handle = async ({ event, resolve }) => { export const handle = async ({ event, resolve }) => {
// Use optional chaining and nullish coalescing for safer property access // Use optional chaining and nullish coalescing for safer property access
const regionHeader = const regionHeader =
event?.request?.headers?.get("x-vercel-id") ?? event?.request?.headers?.get("x-vercel-id") ??
"fra1::fra1::8t4xg-1700258428633-157d82fdfcc7"; "fra1::fra1::8t4xg-1700258428633-157d82fdfcc7";
// Use a more compatible way to get the first element of the split array const ip =
const userRegion = regionHeader.split("::")[0] || ""; event.request.headers.get("x-forwarded-for") ||
event.request.headers.get("remote-address");
const isUsRegion = usRegion.has(userRegion); let isUS = false;
if (ip) {
const geoResponse = await fetch(`https://ipinfo.io/${ip}/geo`);
const geoData = await geoResponse.json();
if (geoData.country === "US") {
isUS = true;
//console.log("yelllo", geoData);
}
}
// Use a ternary operator instead of the logical OR for better compatibility // Use a ternary operator instead of the logical OR for better compatibility
const pbURL = isUsRegion const pbURL = isUS
? import.meta.env.VITE_USEAST_POCKETBASE_URL ? import.meta.env.VITE_USEAST_POCKETBASE_URL
: import.meta.env.VITE_EU_POCKETBASE_URL; : import.meta.env.VITE_EU_POCKETBASE_URL;
const apiURL = isUsRegion const apiURL = isUS
? import.meta.env.VITE_USEAST_API_URL ? import.meta.env.VITE_USEAST_API_URL
: import.meta.env.VITE_EU_API_URL; : import.meta.env.VITE_EU_API_URL;
const fastifyURL = isUsRegion const fastifyURL = isUS
? import.meta.env.VITE_USEAST_FASTIFY_URL ? import.meta.env.VITE_USEAST_FASTIFY_URL
: import.meta.env.VITE_EU_FASTIFY_URL; : import.meta.env.VITE_EU_FASTIFY_URL;
const wsURL = isUsRegion const wsURL = isUS
? import.meta.env.VITE_USEAST_WS_URL ? import.meta.env.VITE_USEAST_WS_URL
: import.meta.env.VITE_EU_WS_URL; : import.meta.env.VITE_EU_WS_URL;

View File

@ -1,333 +1,310 @@
import { createPostTextSchema,createPostImageSchema, createPostLinkSchema } from '$lib/schemas'; import {
import { validateData } from '$lib/utils'; createPostTextSchema,
import { error, fail, redirect } from '@sveltejs/kit'; createPostImageSchema,
import { serialize } from 'object-to-formdata'; createPostLinkSchema,
import { marked } from 'marked'; } from "$lib/schemas";
import { validateData } from "$lib/utils";
import { error, fail, redirect } from "@sveltejs/kit";
import { serialize } from "object-to-formdata";
import { marked } from "marked";
import got from 'got'; import got from "got";
import cheerio from 'cheerio'; import cheerio from "cheerio";
import BlobUtil from 'blob-util'; import * as blobUtil from "blob-util"; // Changed import
import sharp from 'sharp'; import sharp from "sharp";
function removeDuplicateClasses(str) {
return str.replace(
/class="([^"]*)"/,
(match, classAttr) =>
`class="${[...new Set(classAttr.split(" "))].join(" ")}"`
);
}
function addClassesToHtml(htmlString) {
// Helper function to add a class to a specific tag
function addClassToTag(tag, className) {
// Add class if the tag doesn't already have a class attribute
const regex = new RegExp(`<${tag}(?![^>]*\\bclass=)([^>]*)>`, "g");
htmlString = htmlString.replace(regex, `<${tag} class="${className}"$1>`);
export const config = { // Append the new class to tags that already have a class attribute, ensuring no duplicates
runtime: 'nodejs20.x', const regexWithClass = new RegExp(
}; `(<${tag}[^>]*\\bclass=["'][^"']*)(?!.*\\b${className}\\b)([^"']*)["']`,
"g"
);
function removeDuplicateClasses(str) { htmlString = htmlString.replace(regexWithClass, `$1 ${className}$2"`);
return str.replace(/class="([^"]*)"/, (match, classAttr) => `class="${[...new Set(classAttr.split(' '))].join(' ')}"`);
} }
function addClassesToHtml(htmlString) { // Add classes to headings
// Helper function to add a class to a specific tag addClassToTag("h1", "text-lg");
function addClassToTag(tag, className) { addClassToTag("h2", "text-lg");
// Add class if the tag doesn't already have a class attribute addClassToTag("h3", "text-lg");
const regex = new RegExp(`<${tag}(?![^>]*\\bclass=)([^>]*)>`, 'g'); addClassToTag("h4", "text-lg");
htmlString = htmlString.replace(regex, `<${tag} class="${className}"$1>`); addClassToTag("h5", "text-lg");
addClassToTag("h6", "text-lg");
// Append the new class to tags that already have a class attribute, ensuring no duplicates // Add classes to anchor tags
const regexWithClass = new RegExp(`(<${tag}[^>]*\\bclass=["'][^"']*)(?!.*\\b${className}\\b)([^"']*)["']`, 'g'); addClassToTag("a", "text-blue-400 hover:text-white underline");
htmlString = htmlString.replace(regexWithClass, `$1 ${className}$2"`);
}
// Add classes to headings // Add classes to ordered lists
addClassToTag('h1', 'text-lg'); addClassToTag("ol", "list-decimal ml-10 text-sm");
addClassToTag('h2', 'text-lg');
addClassToTag('h3', 'text-lg');
addClassToTag('h4', 'text-lg');
addClassToTag('h5', 'text-lg');
addClassToTag('h6', 'text-lg');
// Add classes to anchor tags // Add classes to unordered lists
addClassToTag('a', 'text-blue-400 hover:text-white underline'); addClassToTag("ul", "list-disc ml-10 text-sm -mt-5");
// Add classes to ordered lists // Add classes to blockquotes and their paragraphs
addClassToTag('ol', 'list-decimal ml-10 text-sm'); function addClassToBlockquote() {
// Add class to blockquote
htmlString = htmlString.replace(
/<blockquote/g,
'<blockquote class="pl-4 pr-4 rounded-lg bg-[#323232]"'
);
// Add classes to unordered lists // Add class to p inside blockquote
addClassToTag('ul', 'list-disc ml-10 text-sm -mt-5'); htmlString = htmlString.replace(
/<blockquote([^>]*)>\s*<p/g,
// Add classes to blockquotes and their paragraphs `<blockquote$1>\n<p class="text-sm font-medium leading-relaxed text-white"`
function addClassToBlockquote() { );
// Add class to blockquote
htmlString = htmlString.replace(
/<blockquote/g,
'<blockquote class="pl-4 pr-4 rounded-lg bg-[#323232]"'
);
// Add class to p inside blockquote
htmlString = htmlString.replace(
/<blockquote([^>]*)>\s*<p/g,
`<blockquote$1>\n<p class="text-sm font-medium leading-relaxed text-white"`
);
}
addClassToBlockquote();
// Remove duplicate classes after all modifications
htmlString = removeDuplicateClasses(htmlString);
return htmlString;
} }
addClassToBlockquote();
export const load = async ({ locals}) => { // Remove duplicate classes after all modifications
htmlString = removeDuplicateClasses(htmlString);
if (!locals.pb.authStore.isValid) { return htmlString;
redirect(303, '/login'); }
}
export const load = async ({ locals }) => {
if (!locals.pb.authStore.isValid) {
redirect(303, "/login");
}
}; };
export const actions = { export const actions = {
createPostText: async ({ request, locals }) => {
createPostText: async ({ request, locals }) => { let newPost = "";
const body = await request.formData();
let newPost = ''; body.delete("thumbnail");
const body = await request.formData(); body.append("user", locals?.user?.id);
body.delete('thumbnail');
body.append('user', locals?.user?.id); let { formData, errors } = await validateData(body, createPostTextSchema);
let {formData, errors} = await validateData( body, createPostTextSchema); formData.description = addClassesToHtml(marked(formData?.description));
formData.description = addClassesToHtml(marked(formData?.description)) formData.tagTopic = JSON.parse(formData.tagTopic)[0];
formData.upvote = 1;
formData.tagTopic = JSON.parse(formData.tagTopic)[0] if (errors) {
formData.upvote = 1 return fail(400, {
data: formData,
errors: errors.fieldErrors,
if(errors) });
{ }
return fail(400, {
data: formData, //Each post gives the user +1 Karma points
errors: errors.fieldErrors await locals.pb.collection("users").update(locals.user.id, {
}) "karma+": 1,
} });
try {
newPost = await locals.pb.collection("posts").create(serialize(formData));
//Each post gives the user +1 Karma points
await locals.pb.collection("users").update(locals.user.id, { // add the tagTopic manually because serialize does not work on arrays
"karma+": 1, await locals?.pb.collection("posts").update(newPost.id, {
}) tagTopic: formData.tagTopic,
});
try {
//Save it collection alreadyVoted to keep track if user voted or not
newPost = await locals.pb.collection('posts').create(serialize(formData)); //FormData for alreadyVoted
let formDataAlreadyVoted = new FormData();
// add the tagTopic manually because serialize does not work on arrays formDataAlreadyVoted.append("post", newPost?.id);
await locals?.pb.collection("posts").update(newPost.id, { formDataAlreadyVoted.append("user", newPost?.user);
"tagTopic": formData.tagTopic, formDataAlreadyVoted.append("type", "upvote");
}) //console.log(formDataAlreadyVoted)
await locals.pb.collection("alreadyVoted").create(formDataAlreadyVoted);
//Save it collection alreadyVoted to keep track if user voted or not } catch (err) {
//FormData for alreadyVoted console.log("Error: ", err);
error(err.status, err.message);
let formDataAlreadyVoted = new FormData(); }
formDataAlreadyVoted.append('post', newPost?.id);
formDataAlreadyVoted.append('user', newPost?.user); if (newPost?.id?.length !== 0) {
formDataAlreadyVoted.append('type', 'upvote'); redirect(303, "/community/post/" + newPost?.id);
//console.log(formDataAlreadyVoted) } else {
await locals.pb.collection('alreadyVoted').create(formDataAlreadyVoted); redirect(303, "/community");
}
},
} catch (err) { createPostImage: async ({ request, locals }) => {
console.log('Error: ', err); let newPost = "";
error(err.status, err.message); const body = await request.formData();
} const thumb = body.get("thumbnail");
if(newPost?.id?.length !== 0) { if (thumb?.size === 0) {
redirect(303, '/community/post/'+newPost?.id); body.delete("thumbnail");
} else { }
redirect(303, '/community');
} body.append("user", locals?.user?.id);
let { formData, errors } = await validateData(body, createPostImageSchema);
}, formData.tagTopic = JSON.parse(formData.tagTopic)[0];
formData.upvote = 1;
createPostImage: async ({ request, locals }) => {
let newPost = ''; if (errors) {
const body = await request.formData(); return fail(400, {
const thumb = body.get('thumbnail'); data: formData,
errors: errors.fieldErrors,
if (thumb?.size === 0) { });
body.delete('thumbnail'); }
}
//Each post gives the user +1 Karma points
body.append('user', locals?.user?.id); await locals.pb.collection("users").update(locals?.user?.id, {
"karma+": 1,
let {formData, errors} = await validateData( body, createPostImageSchema); });
formData.tagTopic = JSON.parse(formData.tagTopic)[0] if (formData.thumbnail.type.includes("image")) {
formData.upvote = 1 try {
const image = formData.thumbnail;
const imageBuffer = await image.arrayBuffer();
if(errors) const imageBufferArray = new Uint8Array(imageBuffer);
{ let optimizedImageBuffer;
return fail(400, { if (image.type === "image/gif") {
data: formData, // Process GIF files differently
errors: errors.fieldErrors optimizedImageBuffer = imageBufferArray;
}) } else {
} // Process other image formats (e.g., JPEG, PNG) using sharp library
optimizedImageBuffer = await sharp(imageBufferArray)
.resize({
width: 800,
//Each post gives the user +1 Karma points height: 1000,
await locals.pb.collection("users").update(locals?.user?.id, { fit: sharp.fit.inside,
"karma+": 1, withoutEnlargement: true,
}) })
.jpeg({ quality: 80 })
.toBuffer();
}
if (formData.thumbnail.type.includes('image')) {
try { formData.thumbnail = new File([optimizedImageBuffer], image.name, {
const image = formData.thumbnail; type: image.type,
const imageBuffer = await image.arrayBuffer(); lastModified: image.lastModified,
const imageBufferArray = new Uint8Array(imageBuffer); });
let optimizedImageBuffer; } catch (err) {
console.log("Error:", err);
if (image.type === 'image/gif') { error(err.status, err.message);
// Process GIF files differently }
optimizedImageBuffer = imageBufferArray; }
} else {
// Process other image formats (e.g., JPEG, PNG) using sharp library try {
optimizedImageBuffer = await sharp(imageBufferArray) newPost = await locals.pb.collection("posts").create(serialize(formData));
.resize({
width: 800, // add the tagTopic manually because serialize does not work on arrays
height: 1000, await locals?.pb.collection("posts").update(newPost.id, {
fit: sharp.fit.inside, tagTopic: formData?.tagTopic,
withoutEnlargement: true, });
})
.jpeg({ quality: 80 }) //Save it collection alreadyVoted to keep track if user voted or not
.toBuffer(); //FormData for alreadyVoted
}
let formDataAlreadyVoted = new FormData();
formData.thumbnail = new File([optimizedImageBuffer], image.name, { formDataAlreadyVoted.append("post", newPost.id);
type: image.type, formDataAlreadyVoted.append("user", newPost.user);
lastModified: image.lastModified, formDataAlreadyVoted.append("type", "upvote");
}); //console.log(formDataAlreadyVoted)
await locals.pb.collection("alreadyVoted").create(formDataAlreadyVoted);
} catch (err) {
} catch (err) { console.log("Error: ", err);
console.log('Error:', err); error(err.status, err.message);
error(err.status, err.message); }
}
} if (newPost?.id?.length !== 0) {
redirect(303, "/community/post/" + newPost?.id);
} else {
redirect(303, "/community");
}
try { },
newPost = await locals.pb.collection('posts').create(serialize(formData)); createPostLink: async ({ request, locals }) => {
let newPost = "";
const body = await request.formData();
// add the tagTopic manually because serialize does not work on arrays const url = body.get("link");
await locals?.pb.collection("posts").update(newPost.id, { let image;
"tagTopic": formData?.tagTopic, let description;
}) let imageBlob;
try {
//Save it collection alreadyVoted to keep track if user voted or not const response = await got(url, {
//FormData for alreadyVoted headers: {
"user-agent":
let formDataAlreadyVoted = new FormData(); "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
formDataAlreadyVoted.append('post', newPost.id); },
formDataAlreadyVoted.append('user', newPost.user); responseType: "buffer",
formDataAlreadyVoted.append('type', 'upvote'); });
//console.log(formDataAlreadyVoted)
await locals.pb.collection('alreadyVoted').create(formDataAlreadyVoted); const $ = cheerio.load(response.body);
//const title = $('head title').text();
} catch (err) { description = $('head meta[property="og:description"]').attr("content");
console.log('Error: ', err); image = $('head meta[property="og:image"]').attr("content");
error(err.status, err.message);
} if (!image) {
let largestSize = 0;
let largestImage = "";
if(newPost?.id?.length !== 0) { $("img").each(async function () {
redirect(303, '/community/post/'+newPost?.id); if (
} else { $(this).attr("src") &&
redirect(303, '/community'); $(this)
} .attr("src")
.match(/\.(webp|jpg|jpeg|png|gif)$/)
) {
}, try {
const imageBuffer = await got(image, {
headers: {
createPostLink: async ({ request, locals }) => { "user-agent":
let newPost = ''; "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
const body = await request.formData(); },
const url = body.get('link') responseType: "buffer",
let image; }).then((response) => response.body);
let description; imageBlob = await blobUtil.createBlob([imageBuffer], {
let imageBlob; // Changed usage
type: "image/jpeg",
try { });
const response = await got(url, { headers: { } catch (error) {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3' // Handle the error when getting the image
}, console.error("Error getting image:", error);
responseType: 'buffer' }); }
}
const $ = cheerio.load(response.body); });
//const title = $('head title').text(); image = largestImage;
description= $('head meta[property="og:description"]').attr('content'); }
image = $('head meta[property="og:image"]').attr('content');
// Download the image and append it to the form data
if (!image) { const imageBuffer = await got(image, {
let largestSize = 0; headers: {
let largestImage = ''; "user-agent":
$('img').each(async function() { "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
if ($(this).attr('src') && $(this).attr('src').match(/\.(webp|jpg|jpeg|png|gif)$/)) { },
try { responseType: "buffer",
const imageBuffer = await got($(this).attr('src'), { headers: {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'},responseType: 'buffer' }).then(response => response.body); }).then((response) => response.body);
const imageSize = (await sharp(imageBuffer).metadata()).width * (await sharp(imageBuffer).metadata()).height; imageBlob = await blobUtil.createBlob([imageBuffer], {
if (imageSize > largestSize) { // Changed usage
largestSize = imageSize; type: "image/jpeg",
largestImage = $(this).attr('src'); });
} } catch (e) {
} catch (error) { console.log(e);
// Handle the error when getting the image }
console.error('Error getting image:', error);
} //body.delete('thumbnail')
} //body.append('thumbnail', imageBlob);
});
image = largestImage; // Append the title to the form data
} //body.append('name', title);
body.append("user", locals.user.id);
body.append("description", description);
// Download the image and append it to the form data
const imageBuffer = await got(image, { headers: {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'},responseType: 'buffer' }).then(response => response.body); /*
imageBlob = await BlobUtil.createBlob([imageBuffer], { type: 'image/jpeg' });
}
catch(e)
{
console.log(e)
}
//body.delete('thumbnail')
//body.append('thumbnail', imageBlob);
// Append the title to the form data
//body.append('name', title);
body.append('user', locals.user.id);
body.append('description', description);
/*
const thumb = body.get('thumbnail'); const thumb = body.get('thumbnail');
if (thumb.size === 0) { if (thumb.size === 0) {
@ -335,63 +312,53 @@ export const actions = {
} }
*/ */
let { formData, errors } = await validateData(body, createPostLinkSchema);
let {formData, errors} = await validateData( body, createPostLinkSchema); formData.tagTopic = JSON.parse(formData.tagTopic)[0];
formData.upvote = 1;
formData.tagTopic = JSON.parse(formData.tagTopic)[0] if (imageBlob?.length !== 0) {
formData.upvote = 1 formData.thumbnail = imageBlob;
}
if (errors) {
return fail(400, {
data: formData,
errors: errors.fieldErrors,
});
}
if (imageBlob?.length !== 0) { //Each post gives the user +1 Karma points
formData.thumbnail = imageBlob await locals.pb.collection("users").update(locals?.user?.id, {
"karma+": 1,
});
} try {
newPost = await locals.pb.collection("posts").create(serialize(formData));
if(errors) // add the tagTopic manually because serialize does not work on arrays
{ await locals.pb.collection("posts").update(newPost.id, {
return fail(400, { tagTopic: formData.tagTopic,
data: formData, });
errors: errors.fieldErrors
})
}
//Save it collection alreadyVoted to keep track if user voted or not
//FormData for alreadyVoted
//Each post gives the user +1 Karma points let formDataAlreadyVoted = new FormData();
await locals.pb.collection("users").update(locals?.user?.id, { formDataAlreadyVoted.append("post", newPost.id);
"karma+": 1, formDataAlreadyVoted.append("user", newPost.user);
}) formDataAlreadyVoted.append("type", "upvote");
//console.log(formDataAlreadyVoted)
try { await locals.pb.collection("alreadyVoted").create(formDataAlreadyVoted);
newPost = await locals.pb.collection('posts').create(serialize(formData)); } catch (err) {
console.log("Error: ", err);
error(err.status, err.message);
// add the tagTopic manually because serialize does not work on arrays }
await locals.pb.collection("posts").update(newPost.id, {
"tagTopic": formData.tagTopic,
})
//Save it collection alreadyVoted to keep track if user voted or not
//FormData for alreadyVoted
let formDataAlreadyVoted = new FormData();
formDataAlreadyVoted.append('post', newPost.id);
formDataAlreadyVoted.append('user', newPost.user);
formDataAlreadyVoted.append('type', 'upvote');
//console.log(formDataAlreadyVoted)
await locals.pb.collection('alreadyVoted').create(formDataAlreadyVoted);
} catch (err) {
console.log('Error: ', err);
error(err.status, err.message);
}
if(newPost?.id?.length !== 0) {
redirect(303, '/community/post/'+newPost?.id);
} else {
redirect(303, '/community');
}
},
if (newPost?.id?.length !== 0) {
redirect(303, "/community/post/" + newPost?.id);
} else {
redirect(303, "/community");
}
},
}; };

View File

@ -1,5 +1,5 @@
//import adapter from '@sveltejs/adapter-static'; //import adapter from '@sveltejs/adapter-static';
import adapter from "@sveltejs/adapter-vercel"; import adapter from "@sveltejs/adapter-node";
import compression from "compression"; import compression from "compression";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"; import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
@ -10,8 +10,6 @@ const config = {
adapter: adapter({ adapter: adapter({
// Add the compression middleware to the adapter options // Add the compression middleware to the adapter options
middleware: (handler) => compression()(handler), middleware: (handler) => compression()(handler),
runtime: "nodejs20.x",
regions: ["fra1"],
worker: true, // Add this line if the adapter supports handling worker files worker: true, // Add this line if the adapter supports handling worker files
}), }),
}, },

View File

@ -1,35 +1,37 @@
import { sveltekit } from '@sveltejs/kit/vite'; import { sveltekit } from "@sveltejs/kit/vite";
import { visualizer } from 'rollup-plugin-visualizer'; import { visualizer } from "rollup-plugin-visualizer";
/** @type {import('vite').UserConfig} */ /** @type {import('vite').UserConfig} */
const config = { const config = {
plugins: [ plugins: [
sveltekit(), sveltekit(),
visualizer({ open: true }) // Plugin to visualize the bundle //visualizer({ open: true }) // Plugin to visualize the bundle
], ],
server: { server: {
cors: true, cors: true,
}, },
build: { build: {
target: 'esnext', target: "esnext",
minify: true, minify: true,
chunkSizeWarningLimit: 500, // Lower this to ensure chunks are appropriately sized chunkSizeWarningLimit: 500, // Lower this to ensure chunks are appropriately sized
rollupOptions: { rollupOptions: {
output: { output: {
manualChunks(id) { manualChunks(id) {
if (id.includes('node_modules')) { if (id.includes("node_modules")) {
return id.toString().split('node_modules/')[1].split('/')[0].toString(); return id
.toString()
.split("node_modules/")[1]
.split("/")[0]
.toString();
} }
} },
} },
}, },
brotliSize: true, // Enable Brotli compression brotliSize: true, // Enable Brotli compression
}, },
optimizeDeps: { optimizeDeps: {
exclude: [ exclude: ["pocketbase"],
'pocketbase', },
],
}
}; };
export default config; export default config;