Skip to content

Commit

Permalink
implement React webpack aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Aug 12, 2024
1 parent 68b8ae0 commit 8d6d56c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions admin/test-bad-package/README.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# test-bad-package

This package declares a wrong React version on purpose
This package declares a wrong React version on purpose (v15.7.0)

The goal is to test that the MD/MDX content of this package can still be rendered by the website.
The goal is to test that the MD/MDX content of this package can still be imported/rendered by our website.

See related issue https://github.com/facebook/docusaurus/issues/9027

Expand Down
9 changes: 9 additions & 0 deletions packages/docusaurus/src/webpack/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ const LibrariesToTranspileRegex = new RegExp(
LibrariesToTranspile.map((libName) => `(node_modules/${libName})`).join('|'),
);

const ReactAliases: Record<string, string> = process.env
.DOCUSAURUS_NO_REACT_ALIASES
? {}
: {
react: path.dirname(require.resolve('react/package.json')),
'react-dom': path.dirname(require.resolve('react-dom/package.json')),
};

export function excludeJS(modulePath: string): boolean {
// Always transpile client dir
if (modulePath.startsWith(clientDir)) {
Expand Down Expand Up @@ -136,6 +144,7 @@ export async function createBaseConfig({
process.cwd(),
],
alias: {
...ReactAliases,
'@site': siteDir,
'@generated': generatedFilesDir,
...(await loadDocusaurusAliases()),
Expand Down

0 comments on commit 8d6d56c

Please sign in to comment.