Skip to content

chore(website): migrate webpack configs to ESM#4351

Closed
yangshun wants to merge 1 commit intomasterfrom
chore/website-webpack-esm
Closed

chore(website): migrate webpack configs to ESM#4351
yangshun wants to merge 1 commit intomasterfrom
chore/website-webpack-esm

Conversation

@yangshun
Copy link
Copy Markdown
Member

@yangshun yangshun commented Mar 8, 2026

Context

The website webpack config stack was still using CommonJS while the rest of the website codebase had already largely moved to lodash-es.

This updates the webpack-related config files to ESM and removes the remaining direct lodash usage from the website package.

Implementation

  • rename the webpack config files and shared parts from .js to .mjs
  • convert the webpack config stack to ESM imports / exports
  • update website scripts and ESLint config to consume the ESM webpack config files correctly
  • add a small CommonJS-only webpack resolver config for eslint-import-resolver-webpack
  • migrate the remaining website lodash usage to lodash-es
  • remove direct lodash and @types/lodash from website/package.json
  • refresh pnpm-lock.yaml

Validation:

  • pnpm exec eslint --ext .js,.mjs .eslintrc.js scripts/build.js scripts/apply-venue-updates.js scripts/fix-venue-name.js scripts/sitemap.js webpack
  • NODE_ENV=development pnpm exec webpack configtest webpack/webpack.config.dev.mjs
  • NODE_ENV=production pnpm exec webpack configtest webpack/webpack.config.browser-warning.mjs
  • NODE_ENV=development pnpm exec webpack configtest webpack/webpack.config.timetable-only.mjs
  • direct Node import of the updated webpack dev / prod configs

Other Information

I did not run a full pnpm --dir website build in this branch.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
nusmods-export Ignored Ignored Mar 8, 2026 8:39am
nusmods-website Ignored Ignored Mar 8, 2026 8:39am

Request Review

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.30%. Comparing base (988c6fd) to head (5b60d4a).
⚠️ Report is 217 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4351      +/-   ##
==========================================
+ Coverage   54.52%   56.30%   +1.77%     
==========================================
  Files         274      308      +34     
  Lines        6076     6962     +886     
  Branches     1455     1682     +227     
==========================================
+ Hits         3313     3920     +607     
- Misses       2763     3042     +279     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 8, 2026

Confidence Score: 4/5

  • Safe to merge; this is a well-structured syntax-level migration with no functional regressions.
  • All functional logic is preserved. The only observable runtime change is that appVersion() is now called once at module load instead of twice, which is an improvement. The dynamic lodash-es import pattern is safe given the current call order in every script. The author explicitly notes a full production build was not run; given the scope of file renames and requireimport churn, a CI build confirmation would add confidence, but the changes are structurally sound.
  • No files require special attention; this is a straightforward ESM migration with correct handling of CJS interop.

Sequence Diagram

sequenceDiagram
    participant CLI as Node CLI (scripts/build.js)
    participant LWM as loadWebpackModules()
    participant PROD as webpack.config.prod.mjs
    participant BO as webpack.config.browser-warning.mjs
    participant TO as webpack.config.timetable-only.mjs
    participant PARTS as webpack.parts.mjs
    participant LES as lodash-es

    CLI->>LWM: await loadWebpackModules()
    par Dynamic ESM imports (Promise.all)
        LWM->>PROD: import(...)
        LWM->>BO: import(...)
        LWM->>TO: import(...)
        LWM->>PARTS: import(...)
        LWM->>LES: import('lodash-es') → castArray
    end
    LWM-->>CLI: { production, timetableOnly, browserWarning, parts }
    CLI->>CLI: buildAll(previousDistFileSizes, webpackModules)
    par Parallel builds
        CLI->>CLI: buildProd({ production, browserWarning, parts })
        CLI->>CLI: buildTimetableOnly({ timetableOnly })
    end
    CLI->>CLI: writeCommitHash(parts)
Loading

Last reviewed commit: 5b60d4a

@ravern
Copy link
Copy Markdown
Member

ravern commented Mar 10, 2026

We had to revert the lodash -> lodash-es changes from #4348 (reverted in #4353) due to a runtime error in the export service.

telegram-cloud-photo-size-5-6154412673605505697-y

Will hold off on this PR for now while investigating.

@yangshun
Copy link
Copy Markdown
Member Author

Yes, thanks for the reminder. I'll also be investigating.

@ravern
Copy link
Copy Markdown
Member

ravern commented Mar 10, 2026

Opened a PR here: #4357

@yangshun
Copy link
Copy Markdown
Member Author

yangshun commented Mar 16, 2026

Let's not bother with this since the noisy warnings no longer show up during development and build (cuz the Babel plugin has been removed).

@yangshun yangshun closed this Mar 16, 2026
@yangshun yangshun deleted the chore/website-webpack-esm branch March 16, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants