Skip to content

Commit

Permalink
Convert next.config.js to a TypeScript file
Browse files Browse the repository at this point in the history
The env property now accepts undefined values, so compact is no longer
needed.
  • Loading branch information
canac committed Nov 25, 2024
1 parent a6f64a7 commit 4cb39e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
20 changes: 8 additions & 12 deletions next.config.js → next.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const bundleAnalyzer = require('@next/bundle-analyzer');
const withPlugins = require('next-compose-plugins');
const withOptimizedImages = require('next-optimized-images');
const withPWA = require('next-pwa');
import type { NextConfig } from 'next';
import bundleAnalyzer from '@next/bundle-analyzer';
import withPlugins from 'next-compose-plugins';
import withOptimizedImages from 'next-optimized-images';
import withPWA from 'next-pwa';

if (process.env.secrets && process.env.secrets !== '{}') {
process.env.JWT_SECRET = JSON.parse(process.env.secrets).JWT_SECRET;
Expand Down Expand Up @@ -29,13 +30,8 @@ const withBundleAnalyzer = bundleAnalyzer({
enabled: process.env.ANALYZE === 'true',
});

// Remove empty strings and missing values from the object
const compact = (obj) =>
Object.fromEntries(Object.entries(obj).filter(([_key, value]) => !!value));

/** @type {import('next').NextConfig} */
const config = {
env: compact({
const config: NextConfig = {
env: {
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
JWT_SECRET: process.env.JWT_SECRET ?? 'development-key',
API_URL: process.env.API_URL ?? 'https://api.stage.mpdx.org/graphql',
Expand Down Expand Up @@ -90,7 +86,7 @@ const config = {
PRIVACY_POLICY_URL: process.env.PRIVACY_POLICY_URL,
TERMS_OF_USE_URL: process.env.TERMS_OF_USE_URL,
DD_ENV: process.env.DD_ENV ?? 'development',
}),
},
// Force .page prefix on page files (ex. index.page.tsx) so generated files can be included in /pages directory without Next.js throwing build errors
pageExtensions: ['page.tsx', 'page.ts', 'page.jsx', 'page.js'],
productionBrowserSourceMaps: true,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"__tests__/jest.d.ts",
"**/*.ts",
"**/*.tsx",
"next.config.js",
"next.config.ts",
"onesky/upload.js",
"onesky/download.js"
],
Expand Down

0 comments on commit 4cb39e9

Please sign in to comment.