Skip to content

Commit

Permalink
Load add-ons
Browse files Browse the repository at this point in the history
  • Loading branch information
pnicolli committed Oct 15, 2024
1 parent dccb8b7 commit 857c572
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
34 changes: 27 additions & 7 deletions apps/nextjs/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
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 = {
// sassOptions: {
// 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() {
Expand Down
5 changes: 5 additions & 0 deletions apps/nextjs/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
3 changes: 2 additions & 1 deletion apps/nextjs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
}
],
"paths": {
"@/*": ["./src/*"]
"@/*": ["./src/*"],
"@root/*": ["./src/*"]
}
},
"include": [
Expand Down

0 comments on commit 857c572

Please sign in to comment.