Skip to content

Toggle NextJS image optimization with an env var #2385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions env/frontend.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
NODE_ENV=development
PORT=8062
SENTRY_ENV=dev # Re-enable sentry
OPTIMIZE_IMAGES="true"

# Environment variables with `NEXT_PUBLIC_` prefix are exposed to the client side
NEXT_PUBLIC_ORIGIN=${MITOL_APP_BASE_URL}
Expand Down
5 changes: 5 additions & 0 deletions frontends/main/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const { validateEnv } = require("./validateEnv")

validateEnv()

const OPTIMIZE_IMAGES = Boolean(
(process.env.OPTIMIZE_IMAGES ?? "true") === "true",
)

const processFeatureFlags = () => {
const featureFlagPrefix =
process.env.NEXT_PUBLIC_POSTHOG_FEATURE_PREFIX || "FEATURE_"
Expand Down Expand Up @@ -90,6 +94,7 @@ const nextConfig = {
transpilePackages: ["@mitodl/smoot-design/ai"],

images: {
unoptimized: !OPTIMIZE_IMAGES,
remotePatterns: [
{
protocol: "http",
Expand Down
Loading