103 lines
3.1 KiB
JavaScript
103 lines
3.1 KiB
JavaScript
import withMintelConfig from "@mintel/next-config";
|
|
import { withPayload } from '@payloadcms/next/withPayload';
|
|
import createMDX from '@next/mdx';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const filename = fileURLToPath(import.meta.url);
|
|
const dirname = path.dirname(filename);
|
|
|
|
/** @type {import('next').NextConfig} */
|
|
const nextConfig = {
|
|
serverExternalPackages: [
|
|
'canvas',
|
|
'sharp',
|
|
'puppeteer',
|
|
'require-in-the-middle',
|
|
'import-in-the-middle'
|
|
],
|
|
transpilePackages: [
|
|
'@mintel/content-engine',
|
|
'@mintel/concept-engine',
|
|
'@mintel/estimation-engine',
|
|
'@mintel/meme-generator',
|
|
'@mintel/payload-ai',
|
|
'@mintel/pdf',
|
|
'@mintel/thumbnail-generator'
|
|
],
|
|
images: {
|
|
remotePatterns: [
|
|
{
|
|
protocol: 'https',
|
|
hostname: '*.your-objectstorage.com',
|
|
},
|
|
{
|
|
protocol: 'https',
|
|
hostname: 'fsn1.your-objectstorage.com',
|
|
},
|
|
],
|
|
},
|
|
async redirects() {
|
|
return [
|
|
{
|
|
source: '/case-studies/klz',
|
|
destination: '/case-studies/klz-cables',
|
|
permanent: true,
|
|
},
|
|
];
|
|
},
|
|
outputFileTracingRoot: path.join(dirname, '../../'),
|
|
};
|
|
|
|
const withMDX = createMDX({});
|
|
|
|
// Execute wrappers
|
|
let config = withPayload(withMintelConfig(withMDX(nextConfig)));
|
|
|
|
/**
|
|
* Injects our critical showcase rewrites into a resolved Next.js config object.
|
|
*/
|
|
function injectShowcaseRewrites(resolvedConfig) {
|
|
const originalRewrites = resolvedConfig.rewrites;
|
|
|
|
resolvedConfig.rewrites = async () => {
|
|
const existing = await originalRewrites?.() || [];
|
|
|
|
// Normalize existing to object pattern
|
|
const normalized = Array.isArray(existing)
|
|
? { afterFiles: existing, beforeFiles: [], fallback: [] }
|
|
: existing;
|
|
|
|
return {
|
|
...normalized,
|
|
beforeFiles: [
|
|
...(normalized.beforeFiles || []),
|
|
// Diagnostic rule
|
|
{ source: '/robots-test', destination: '/robots.txt' },
|
|
// Showcase Assets
|
|
{ source: '/assets/:path*', destination: '/showcase/klz-cables.com/assets/:path*' },
|
|
{ source: '/wp-content/:path*', destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-content/:path*' },
|
|
{ source: '/wp-includes/:path*', destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-includes/:path*' },
|
|
{ source: '/:folder(case-studies|work|blog)/assets/:path*', destination: '/showcase/klz-cables.com/assets/:path*' },
|
|
{ source: '/:folder(case-studies|work|blog)/wp-content/:path*', destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-content/:path*' },
|
|
{ source: '/:folder(case-studies|work|blog)/wp-includes/:path*', destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-includes/:path*' },
|
|
],
|
|
};
|
|
};
|
|
|
|
return resolvedConfig;
|
|
}
|
|
|
|
// Handle both standard objects and functional wrappers (like withPayload)
|
|
if (typeof config === 'function') {
|
|
const originalConfigWrapper = config;
|
|
config = async (phase, args) => {
|
|
const resolved = await originalConfigWrapper(phase, args);
|
|
return injectShowcaseRewrites(resolved);
|
|
};
|
|
} else {
|
|
config = injectShowcaseRewrites(config);
|
|
}
|
|
|
|
export default config;
|