From c7fe75829f3c3f916cc2a5ca206c3511b9c33033 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Sat, 17 Feb 2024 16:52:32 -0800 Subject: [PATCH] Export Frontend: first steps Note: needs deletion of app/api/trpc-node/[trpc]/route.ts due to an upstream issue --- next.config.mjs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/next.config.mjs b/next.config.mjs index 88551d90df..61974ca23e 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,13 +1,24 @@ +const BuildOptions = { + // Future: Electron/Frontend-only builds + exportFrontend: false, +}; + /** @type {import('next').NextConfig} */ let nextConfig = { reactStrictMode: true, - // Note: disabled to chech whether the project becomes slower with this - // modularizeImports: { - // '@mui/icons-material': { - // transform: '@mui/icons-material/{{member}}', - // }, - // }, + // [exporting] https://nextjs.org/docs/advanced-features/static-html-export + ...BuildOptions.exportFrontend && { + // Export the frontend to ./dist + output: 'export', + distDir: 'dist', + + // Disable Image optimization + images: { unoptimized: true }, + + // Optional: Change links `/me` -> `/me/` and emit `/me.html` -> `/me/index.html` + // trailingSlash: true, + }, // [puppeteer] https://github.com/puppeteer/puppeteer/issues/11052 experimental: { @@ -24,9 +35,20 @@ let nextConfig = { layers: true, }; + // [exporting] prevent too many small files (50kb) + if (BuildOptions.exportFrontend) + config.optimization.splitChunks.minSize = 50 * 1024; + return config; }, + // Note: disabled to check whether the project becomes slower with this + // modularizeImports: { + // '@mui/icons-material': { + // transform: '@mui/icons-material/{{member}}', + // }, + // }, + // Uncomment the following leave console messages in production // compiler: { // removeConsole: false,