Created
February 6, 2025 07:23
-
-
Save rizkyanas25/c08e54a9a6b30d0f8898beddf642b9be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const NextFederationPlugin = require('@module-federation/nextjs-mf') | |
const SentryWebpackPlugin = require('@sentry/webpack-plugin') | |
/** @type {import('next').NextConfig} */ | |
const nextConfig = { | |
basePath: process.env.NEXT_PUBLIC_ENTRYPOINT | |
? process.env.NEXT_PUBLIC_ENTRYPOINT | |
: undefined, | |
reactStrictMode: true, | |
images: { | |
remotePatterns: [ | |
{ | |
protocol: 'https', | |
hostname: '**.shipper.id', | |
}, | |
{ | |
protocol: 'https', | |
hostname: '**.amazonaws.com', | |
}, | |
], | |
}, | |
publicRuntimeConfig: { | |
'shipper-cdn': process.env.SHIPPER_CDN, | |
'app-env': process.env.APP_ENVIRONMENT, | |
'graphql-url': process.env.GRAPHQL_URL, | |
'cookies-domain': process.env.COOKIES_DOMAIN, | |
'client-id': process.env.GRAPHQL_CLIENT_ID, | |
'client-id-register': process.env.GRAPHQL_CLIENT_ID_REGISTER, | |
'pusher-key': process.env.PUSHER_KEY, | |
'pusher-cluster': process.env.PUSHER_CLUSTER, | |
'media-service': process.env.MEDIASVC_URL, | |
'media-upload': process.env.MEDIASVC_UPLOAD_PATH, | |
'mixpanel-key': process.env.MIXPANEL_KEY, | |
'mixpanel-domain': process.env.MIXPANEL_DOMAIN, | |
'sentry-dsn': process.env.SENTRY_DSN, | |
'sentry-auth': process.env.SENTRY_AUTH, | |
version: process.env.SHIPPER_APP_VERSION, | |
'email-verification-link': process.env.VERIFICATION_LINK, | |
'app-name': process.env.APP_ENTRY, | |
'gtm-key': process.env.GTM_KEY, | |
'oauth-key-google-clientid': process.env.OAUTH_KEY_GOOGLE_CLIENTID, | |
'oauth-key-google-domain': process.env.OAUTH_KEY_GOOGLE_DOMAIN, | |
'default-account-id-menu': process.env.DEFAULT_ACCOUNT_ID_MENU, | |
'captcha-site-key': process.env.CAPTCHA_SITE_KEY, | |
'freshchat-token': process.env.FRESHCHAT_TOKEN, | |
'freshchat-host-url': process.env.FRESHCHAT_HOST_URL, | |
'freshchat-widget-uuid': process.env.FRESHCHAT_WIDGET_UUID, | |
'remote-mfe-fulfillment-url': process.env.REMOTE_MFE_FULFILLMENT_URL, | |
'remote-mfe-shipping-url': process.env.REMOTE_MFE_SHIPPING_URL, | |
'base-path': process.env.NEXT_PUBLIC_ENTRYPOINT, | |
'google-api-key': process.env.GOOGLE_API_KEY, | |
}, | |
serverRuntimeConfig: { | |
// Will only be available on the server side | |
'remote-mfe-shipping-internal-url': | |
process.env.REMOTE_MFE_SHIPPING_INTERNAL_URL, | |
'remote-mfe-fulfillment-internal-url': | |
process.env.REMOTE_MFE_FULFILLMENT_INTERNAL_URL, | |
}, | |
async headers() { | |
return [ | |
{ | |
source: '/(.*)', | |
headers: [ | |
{ | |
key: 'X-Frame-Options', | |
value: 'SAMEORIGIN', | |
}, | |
{ | |
key: 'Content-Security-Policy', | |
value: "frame-ancestors 'self'", | |
}, | |
], | |
}, | |
] | |
}, | |
webpack: (config, options) => { | |
config.plugins.push( | |
new NextFederationPlugin({ | |
name: 'ocms', | |
filename: 'static/chunks/remoteEntry.js', | |
remotes: {}, | |
shared: { | |
'@stitches/react': { | |
eager: true, | |
singleton: true, | |
requiredVersion: false, | |
}, | |
'react-intl': { | |
eager: true, | |
singleton: true, | |
requiredVersion: false, | |
}, | |
'@apollo/client': { | |
singleton: true, | |
requiredVersion: false, | |
eager: true, | |
}, | |
dayjs: { | |
singleton: true, | |
requiredVersion: false, | |
eager: true, | |
}, | |
'react-day-picker': { | |
singleton: true, | |
requiredVersion: false, | |
eager: true, | |
}, | |
'react-toastify': { | |
singleton: true, | |
requiredVersion: false, | |
eager: true, | |
}, | |
'@shipper/i18next': { | |
singleton: true, | |
requiredVersion: false, | |
eager: true, | |
}, | |
'mixpanel-browser': { | |
singleton: true, | |
requiredVersion: false, | |
eager: true, | |
}, | |
'next/image': { | |
singleton: true, | |
requiredVersion: false, | |
eager: true, | |
}, | |
'file-saver': { | |
singleton: true, | |
requiredVersion: false, | |
eager: true, | |
}, | |
}, | |
}) | |
) | |
config.module.rules.push({ | |
test: /\.(graphql|gql)$/, | |
exclude: /node_modules/, | |
loader: 'graphql-tag/loader', | |
}) | |
config.module.rules.push({ | |
test: /\.md$/i, | |
use: 'raw-loader', | |
}) | |
if ( | |
process.env.SENTRY_DSN && | |
process.env.SHIPPER_APP_VERSION && | |
process.env.SENTRY_AUTH | |
) { | |
config.plugins.push( | |
new SentryWebpackPlugin({ | |
org: 'shipper', | |
project: 'shipper-ocms-web', | |
include: '.next', | |
urlPrefix: '~/_next', | |
ignore: ['node_modules'], | |
release: process.env.SHIPPER_APP_VERSION, | |
configFile: 'sentry.properties', | |
authToken: process.env.SENTRY_AUTH, | |
sourceMapReference: false, | |
}) | |
) | |
} | |
return config | |
}, | |
assetPrefix: process.env.SHIPPER_CDN || undefined, | |
i18n: { | |
locales: ['id', 'en', 'cn', 'th'], | |
defaultLocale: 'id', | |
localeDetection: false, | |
}, | |
rewrites: async () => { | |
return [ | |
{ | |
source: '/metrics', | |
destination: '/api/metrics', | |
}, | |
] | |
}, | |
redirects: async () => { | |
return [ | |
{ | |
source: '/.(.*)', | |
destination: '/', | |
permanent: true, | |
}, | |
{ | |
source: '/..(.*)', | |
destination: '/404', | |
permanent: true, | |
}, | |
{ | |
source: '/(.*)..', | |
destination: '/404', | |
permanent: true, | |
}, | |
{ | |
source: '/(.*)/./(.*)', | |
destination: '/404', | |
permanent: true, | |
}, | |
] | |
}, | |
} | |
module.exports = nextConfig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment