diff --git a/apps/nextjs/next.config.mjs b/apps/nextjs/next.config.mjs index 9891677772..956f1c5be8 100644 --- a/apps/nextjs/next.config.mjs +++ b/apps/nextjs/next.config.mjs @@ -1,4 +1,9 @@ import path from 'path'; +import AddonConfigurationRegistry from '@plone/registry/src/addon-registry'; +import createAddonsLoader from '@plone/registry/src/create-addons-loader'; + +const projectRootPath = path.resolve('.'); +const registry = new AddonConfigurationRegistry(projectRootPath); /** @type {import('next').NextConfig} */ const nextConfig = { @@ -6,14 +11,29 @@ const nextConfig = { // includePaths: [path.join(__dirname, 'src/lib/components/src/styles')], // }, - // webpack(config) { - // config.resolve.alias = { - // ...config.resolve.alias, - // '../fonts': path.resolve(__dirname, 'src/lib/components/src/fonts'), - // }; + webpack( + config, + // { buildId, dev, isServer, defaultLoaders, nextRuntime, webpack }, + ) { + const addonsLoaderPath = createAddonsLoader( + registry.getAddonDependencies(), + registry.getAddons(), + ); - // return config; - // }, + config.resolve.alias = { + ...config.resolve.alias, + '../fonts': path.resolve('src/lib/components/src/fonts'), + ...registry.getAddonCustomizationPaths(), + ...registry.getAddonsFromEnvVarCustomizationPaths(), + ...registry.getProjectCustomizationPaths(), + 'load-volto-addons': addonsLoaderPath, + ...registry.getResolveAliases(), + }; + + return config; + }, + + transpilePackages: Object.keys(registry.packages), // Rewrite to the backend to avoid CORS async rewrites() { diff --git a/apps/nextjs/src/config/index.ts b/apps/nextjs/src/config/index.ts index 6af6344a8b..5198c1f8a9 100644 --- a/apps/nextjs/src/config/index.ts +++ b/apps/nextjs/src/config/index.ts @@ -1,12 +1,17 @@ import config from '@plone/registry'; +// @ts-expect-error - load-volto-addons is generated by webpack on the fly, see next.config.mjs +import applyAddonConfiguration, { addonsInfo } from 'load-volto-addons'; import Page from '@/views/Page/Page'; +applyAddonConfiguration(config); + config.settings = { ...config.settings, apiPath: process.env.NEXT_PUBLIC_VERCEL_URL ? // Vercel does not prepend the schema to the NEXT_PUBLIC_VERCEL_URL automatic env var `https://${process.env.NEXT_PUBLIC_VERCEL_URL}` : 'http://localhost:3000', + addonsInfo, }; config.views = { diff --git a/apps/nextjs/tsconfig.json b/apps/nextjs/tsconfig.json index 4b7888fa43..92f99a6960 100644 --- a/apps/nextjs/tsconfig.json +++ b/apps/nextjs/tsconfig.json @@ -19,7 +19,8 @@ } ], "paths": { - "@/*": ["./src/*"] + "@/*": ["./src/*"], + "@root/*": ["./src/*"] } }, "include": [