prod build fix

This commit is contained in:
2025-09-16 08:49:25 +02:00
parent 56a88f0a68
commit cbf2e3c738
3 changed files with 37 additions and 9 deletions

View File

@@ -1,3 +1,10 @@
const path = require('path');
let TsconfigPathsPlugin;
try {
// Optional: only used if installed
TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
} catch (_) {}
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
@@ -11,17 +18,37 @@ const nextConfig = {
},
// Enable standalone output for better Docker compatibility
output: 'standalone',
webpack: (config, { isServer, dev }) => {
config.resolve.alias = {
...config.resolve.alias,
'@': require('path').join(__dirname, 'src'),
};
// Optional: Add debug logging
webpack: (config, { dev }) => {
// Ensure resolve object exists
config.resolve = config.resolve || {};
config.resolve.alias = config.resolve.alias || {};
// Hard-set robust alias for "@" => <repo>/src
config.resolve.alias['@'] = path.resolve(__dirname, 'src');
// Ensure common extensions are resolvable
const exts = config.resolve.extensions || [];
config.resolve.extensions = Array.from(new Set([...exts, '.ts', '.tsx', '.js', '.jsx']));
// Add tsconfig-aware resolver plugin if available
if (TsconfigPathsPlugin) {
const existing = config.resolve.plugins || [];
existing.push(
new TsconfigPathsPlugin({
configFile: path.resolve(__dirname, 'tsconfig.json'),
extensions: config.resolve.extensions,
mainFields: ['browser', 'module', 'main'],
})
);
config.resolve.plugins = existing;
}
// Optional: Add debug logging in development
if (dev) {
// eslint-disable-next-line no-console
console.log('Webpack alias config:', config.resolve.alias);
}
return config;
},
env: {