Skip to content

feat(v2): Webpack 5, PostCSS 8 - #4089

Merged
slorber merged 157 commits into
facebook:masterfrom
RDIL:webpack-5
Apr 30, 2021
Merged

slorber merged 157 commits into
facebook:masterfrom
RDIL:webpack-5

Conversation

@RDIL

@RDIL RDIL commented Jan 22, 2021 •

Copy link
Copy Markdown
Contributor

PR by @RDIL & @slorber

Issue: #4027

Released in 2.0.0-alpha.75


Breaking changes

As it's a major Webpack version upgrade, it is a breaking change and can require adapt things on your sites such as the configureWebpack of your custom plugins.

However, sites that do not have custom plugins and mostly use a basic config should be able to upgrade seamlessly.

Please report any issues otherwise.

Known issues:

Using persistent caching

Make your CI cache the node_modules/.cache folder across 2 CI builds, and the 2nd build becomes much faster.


  • Upgrade Webpack 4 to Webpack 5 + upgrade related libs
  • PostCSS 7 to PostCSS 8
  • Leverage persistent caching for a much faster 2nd build
  • Try to keep retro compatibility in most cases (breaking changes are normally all in libs, not Docusaurus)

If you get some deprecation warnings, please report them here with the stacktrace, by running NODE_OPTIONS='--trace-warnings' yarn build


Tested on a lot of sites with great success:

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jan 22, 2021
@netlify

netlify Bot commented Jan 22, 2021 •

Copy link
Copy Markdown

[V2]

Built with commit 867d034

https://deploy-preview-4089--docusaurus-2.netlify.app

@netlify

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment thread packages/docusaurus/src/webpack/utils.ts
@anshulrgoyal

This comment has been minimized.

@RDIL

This comment has been minimized.

Comment thread .eslintrc.js Outdated
Comment thread packages/docusaurus/package.json Outdated
@github-actions

github-actions Bot commented Feb 11, 2021 •

Copy link
Copy Markdown

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 73
🟢 Accessibility 96
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4089--docusaurus-2.netlify.app/

@slorber

slorber commented Apr 23, 2021

Copy link
Copy Markdown
Collaborator

So, I tested this on a lot of sites (cf list at the top) and it seems to work great in most cases, just noted a few minor changes to do.

We'll likely do one last Webpack 4 bugfix release soon and then merge this PR next week.

@juzhiyuan

Copy link
Copy Markdown
Contributor

Glad to receive your PR! @slorber And if it's ready to merge, just let us know :)

slorber added 2 commits April 27, 2021 16:42
# Conflicts:
#	packages/docusaurus-init/templates/bootstrap/package.json
slorber added a commit that referenced this pull request Apr 30, 2021
> Conflict: Multiple assets emit different content to the same filename assets/ideal-img/datagit.100.png
see #4089 (comment)
@slorber

slorber commented Apr 30, 2021

Copy link
Copy Markdown
Collaborator

going to merge/release this, and add another PR for the asset modules, as there are some details I'm not yet able to solve

@slorber
slorber merged commit 05e7250 into facebook:master Apr 30, 2021
@RDIL
RDIL deleted the webpack-5 branch April 30, 2021 16:44
@RDIL

RDIL commented Apr 30, 2021

Copy link
Copy Markdown
Contributor Author

🎉 🎉 🎉

@slorber

slorber commented Apr 30, 2021

Copy link
Copy Markdown
Collaborator

Thanks for your work on this @RDIL ! happy to get this finally merged

slorber added a commit that referenced this pull request Apr 30, 2021
> Conflict: Multiple assets emit different content to the same filename assets/ideal-img/datagit.100.png
see #4089 (comment)
facebook-github-bot pushed a commit to facebook/hermes that referenced this pull request May 5, 2021
Summary:
Use an unreleased version of Docusaurus to test the webpack5 support works for this site, detect potential problems, and perf improvements.

See also facebook/docusaurus#4089

Pull Request resolved: #500

Reviewed By: dulinriley

Differential Revision: D28129952

Pulled By: Huxpro

fbshipit-source-id: 07942b60d5200ea6dc3a9de86844da349f700a31
facebook-github-bot pushed a commit to facebook/relay that referenced this pull request May 21, 2021
Summary:
Use an unreleased version of Docusaurus to test the webpack5 support works for this site, detect potential problems, and perf improvements.

See also facebook/docusaurus#4089

Perf improvements
- First build (local): 300s
- Second build (local): 90s

To get the benefits, it requires caching `node_modules/.cache`.
It is not possible in GH actions, so I suggest migrating the site to Netlify and use the appropriate toml config (example: https://github.com/react-navigation/react-navigation.github.io/pull/974/files)

 ---

Unrelated suggestion: Relay has a lot of versions and long build/start times

Assuming nobody ever edit Relay docs of 2 years ago, you can improve the DX by limiting the number of versions display in dev with this docs plugin config:

```
          onlyIncludeVersions:
            (isDev || isDeployPreview)
              ? ['current', ...versions.slice(0, 2)]
              : undefined,
```

For faster prod build, you can also move older docs to standalone deployments and link to them (see Jest for versions < 25 => https://jestjs.io/)

Pull Request resolved: #3469

Reviewed By: rbalicki2

Differential Revision: D28127629

Pulled By: jstejada

fbshipit-source-id: c78309aa1c7f14f22ecc33166ad5dce7d2e51f94
mrizwanashiq pushed a commit to mrizwanashiq/docusaurus that referenced this pull request Jun 25, 2026
* Initial webpack 5 work

* It works on my machine (lol)

* Committing a bit more work

* It works - sorta

* Update packages/docusaurus/package.json

* at least fix prettier /shrug

* making more progress. build should work now, css stuff is still a bit broken

* Terser things

Signed-off-by: Reece Dunham <me@rdil.rocks>

* Working on things

* Vendor webpack

* Repair chunks, and tests

* Rerun prettier

* Re-add client prefetching

* Update snapshots

* Update snapshots

* I hope this works

* Remove redundant dev server code

* relock

* Trying to reduce memory usage and fix things

* Dead code elim

* Search bar works!!!

* Prefetching should work again

* lock

* ts issue

* Repair snapshot

* Run prettier

* Fix the CI for now

* fix lint-prettier

* clean-css works, now for the other one

* Fix lockfile

* Fixes prettier

* Other css minification works!!!

* Add clean-css options, fix webpack versions

Signed-off-by: Reece Dunham <me@rdil.rocks>

* Fix tests and several of the webpack loaders

Signed-off-by: Reece Dunham <me@rdil.rocks>

* Re-add support for simple css minifier

* Update other related dependencies

* Fix lockfile

* Dev server fixups

Signed-off-by: Reece Dunham <me@rdil.rocks>

* Simplify css things

* Update webpack, try with postcss 7

* Other cssnano repairs

* fix lockfile

* Clean up the babel preset

* Fix lockfile

* Bump RL SSR version

* Fix the build errors

* Lockfile fix

* It works again

* webpack 5 should close compiler after run

* add proper webpack5 persistent caching config

* upgrade webpack deps again

* reduce build perf timeouts to avoid build time regressions

* test if incremental build can run on netlify

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* test

* test

* test

* test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* fix existsSync() calls

* replace @ts-nocheck by a temporary Webpack type

* replace @ts-nocheck by a temporary Webpack type

* replace @ts-nocheck by a temporary Webpack type

* migrate existing stats.warningsFilter to config.ignoreWarnings

* remove stats from postBuild lifecycle data doc, as it is likely unused (we'll add it back if someone ask for it)

* improve build.ts TS issues + move some sync code to async

* cleanup TS of start.ts

* fix TS error

* fix TS issues

* fix TS issues

* fix ts error

* netlify test

* netlify test

* netlify test

* netlify test

* netlify test

* script cleanup

* script cleanup

* re-enable @typescript-eslint/ban-ts-comment

* Deprecate getCacheLoader / getBabelLoader but keep retrocompatibility

* useless TS

* fix and comment gca(chunkName) prefetching function

* remove deprecated mainTemplate.requireFn

* temporarily use react-loadable-ssr-addon-v5-slorber until PR merged: facebook#4089

* comment unsafeCache option

* add explicit and more precise webpack targets

* splitChunks, use new type: "css/mini-extract" as it seems recommended for webpack 5

* webpack error handling:
- log error.details as documented
- keep using react-dev-utils/formatWebpackMessages for now

* fix webpack5 warnings for evalSourceMapMiddleware.js

* typo

* rename webpackHotDevClient

* make all modifications of react-dev-utils explicit with a comment

* revert LogPlugin adapter

* loader-utils update

* add useful share cache comment

* add useful comments regarding the null-loader used in SSR for css files

* upgrade webpack-merge in a retrocompatible way

* use MiniCssExtractPlugin.emit false as recommended

* use @docusaurus/responsive-loader

* revert MiniCssExtractPlugin esModule: false change

* add link to PR for custom CleanWebpackPlugin

* pwa: add fallback to env variable or webpack 5 fails to build

* upgrade to CssMinimizerPlugin 2.0

* only build en locale for windows tests

* line breaks between errors

* add useful comment

* Fix e2e tests with Yarn2 not finding new init template dependencies

* fix bad import

* disable browserslist target as webpack already tries to use browserlists if a config is found, and it is a problem for existing sites

* webpack5 TS fixes

* fix getMinimizer order (even if it does not work yet)

* update postcss to v8, fix cssnano minimizer errors

* add NavbarItem position to types (useful for QuestDB site upgrade to Webpack5)

* add webpack cache env variable to reduce risk of webpack 5 adoption

Co-authored-by: slorber <lorber.sebastien@gmail.com>
mrizwanashiq pushed a commit to mrizwanashiq/docusaurus that referenced this pull request Jun 25, 2026
> Conflict: Multiple assets emit different content to the same filename assets/ideal-img/datagit.100.png
see facebook#4089 (comment)
sparanoid pushed a commit to sparanoid/docusaurus that referenced this pull request Oct 12, 2026
> Conflict: Multiple assets emit different content to the same filename assets/ideal-img/datagit.100.png
see facebook#4089 (comment)
sparanoid pushed a commit to sparanoid/docusaurus that referenced this pull request Oct 12, 2026
> Conflict: Multiple assets emit different content to the same filename assets/ideal-img/datagit.100.png
see facebook#4089 (comment)
slorber added a commit that referenced this pull request Oct 23, 2026
* chore: remove tooling config entries for paths that no longer exist (AI-assisted)

- jest/vendor (cspell, stylelint, oxfmt): removed with the Vitest migration, #12010
- packages/create-docusaurus/templates/facebook (ESLint): removed in #9026
- website/docusaurus.config.js (oxfmt): the config is TypeScript since #9317
- packages/docusaurus-migrate/lib (Vitest): package removed in #9400
- website/netlifyDeployPreview (.gitignore): removed in #4447
- .cache-loader (.gitignore): cache-loader removed with Webpack 5, #4089
- commented-out website/i18n/fr negations (.gitignore)
- ".svg" (oxfmt): typo for the "*.svg" pattern right below it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(knip): treat configuration hints as errors, ignore the ideal-image fork internals (AI-assisted)

- Add treatConfigHintsAsErrors, and remove the 3 entries Knip reports as
  useless: the playwright binary, and the @docusaurus/plugin-css-cascade-layers
  and @mdx-js/react dependencies
- Don't treat the react-ideal-image fork modules as theme component entries,
  so that Knip reports the unused ones

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: remove unused test fixtures (AI-assisted)

- docs bad-id-site and bad-slug-on-doc-home-site: unused since #3245
- utils vcs simple-site: unused since #11512

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(website): fix the React-DOM version check of the bad package dogfood test (AI-assisted)

The second check tested ReactVersion again, so a bad React-DOM version
never threw. Introduced in #10391.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: remove more stale config entries (AI-assisted)

- .gitignore types: nothing generates a types dir, even in #1490 where it
  was added, and it ignores any new types/ source folder
- .gitignore website/rspack-tracing.json: the Rspack trace is written to
  rspack-tracing.pftrace since #11290
- clear script --ignore docusaurus: protected the lib/ sources of the v1
  "docusaurus" package, removed in #4902
- ESLint __mocks__ ignore: converted from .eslintignore in #12024, it only
  matches a root __mocks__ dir that doesn't exist
- Syncpack type-alias group: only the exact @types/react version still
  needs it, the * ranges are gone since #12435 and the other dependencies
  use the catalog since #12696

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: replace the Prettier and Jest leftovers (AI-assisted)

The monorepo formats with oxfmt since #11824 and tests with Vitest since #12010

- Devcontainer: format with the Oxc extension instead of Prettier, which
  formatted with its defaults, and remove the Jest extension
- README: remove the Prettier and Jest badges
- CONTRIBUTING: the formatter is oxfmt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: breaking change Existing sites may not build successfully in the new version. Description contains more details.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Webpack 5: deterministic output, better build performance and caching Chrome Debugger/source maps are inaccurate

9 participants