Repository navigation
Conversation
|
Deploy preview for docusaurus-2 ready! Built with commit 8e3de19 |
|
@SamChou19815 I'd like to have most of the Yarn v2 pnp compatibility completed before we launch the next alpha version. Do you know what else is needed? |
All the changes that need to happen in docusaurus core is done. There is one remaining piece: webpack module resolution. Webpack v4 doesn't support pnp natively, but can be made to support it via a plugin. (See https://yarnpkg.com/features/pnp#support-via-plugins). Fortunately, this can be already done in the user land via docusaurus plugins, like I did for my personal repo: https://github.com/SamChou19815/website/pull/528/files. @yangshun I wonder what's your opinion on this? There are two good options available:
|
|
Thanks for the explanation! I'd go for adding to @docusaurus/core if there are negligible costs to non-pnp users in doing so. What do you recommend? |
I recommend adding it to core. The size of |
Motivation
This diff continues the progress of making docusaurus v2 work under yarn v2's pnp mode.
The Problem
There is a tricky require inside
@docusaurus/theme-classic:@docusaurus/theme-classicalso declareswebpackas a peer dependency. Currently at runtime,webpackis likely to be provided by@docusaurus/core, which declares it as a direct dependency. However, this setup is theoretically not guaranteed to work, and it will certainly break in Yarn v2 pnp's strict mode. To understand why it's the issue, let me draw an layout of the node_modules.In a package manager doesn't implement any hoisting optimization, the layout will be like
Therefore, when
index.jsrequirewebpackit will fail, because it doesn't exist in these paths:project-root/@docusaurus/theme-classic/node_modulesproject-root/@docusaurus/node_modulesproject-root/node_modulesThe current setup happens to work because popular package managers implement hoisting optimization, which results in a layout like
Under yarn's pnp mode, things will break. Although Yarn knows that
@docusaurus/theme-classicdeclareswebpackas a peer dependency, it still doesn't know where to find it.The Fix
I think the code author's intention is to use the
webpackprovided by@docusaurus/core. Therefore, I decide to make this more explicit by usingModule.createRequire, which can be understood by Yarn's pnp runtime. I discussed howcreateRequireworks in #2789.Have you read the Contributing Guidelines on pull requests?
Yes.
Test Plan
Everything can still be properly loaded, and the preview site still works.
Related PRs
(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)