mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-04 10:27:52 +02:00
refactor(v2): add better error message for yarn workspace/monorepo/terser issue (#3619)
* Helpful error message when monorep Terser issue happens * remove optional chaining usage for node < 14, as I'm not sure this file is transpiled properly (not TS) * remove useless doMinify arg
This commit is contained in:
parent
003b457c88
commit
91256d445e
1 changed files with 33 additions and 9 deletions
|
@ -120,13 +120,37 @@ async function doRender(locals) {
|
|||
});
|
||||
|
||||
// Minify html with https://github.com/DanielRuf/html-minifier-terser
|
||||
return minify(renderedHtml, {
|
||||
removeComments: true,
|
||||
removeRedundantAttributes: true,
|
||||
removeEmptyAttributes: true,
|
||||
removeScriptTypeAttributes: true,
|
||||
removeStyleLinkTypeAttributes: true,
|
||||
useShortDoctype: true,
|
||||
minifyJS: true,
|
||||
});
|
||||
function doMinify() {
|
||||
return minify(renderedHtml, {
|
||||
removeComments: true,
|
||||
removeRedundantAttributes: true,
|
||||
removeEmptyAttributes: true,
|
||||
removeScriptTypeAttributes: true,
|
||||
removeStyleLinkTypeAttributes: true,
|
||||
useShortDoctype: true,
|
||||
minifyJS: true,
|
||||
});
|
||||
}
|
||||
|
||||
// TODO this is a temporary error affecting only monorepos due to Terser 5 (async) being used by html-minifier-terser,
|
||||
// instead of the expected Terser 4 (sync)
|
||||
// TODO, remove this once we upgrade everything to Terser 5 (https://github.com/terser/html-minifier-terser/issues/46)
|
||||
// See also
|
||||
// - https://github.com/facebook/docusaurus/issues/3515
|
||||
// - https://github.com/terser/html-minifier-terser/issues/49
|
||||
try {
|
||||
return doMinify();
|
||||
} catch (e) {
|
||||
if (
|
||||
e.message &&
|
||||
e.message.includes("Cannot read property 'replace' of undefined")
|
||||
) {
|
||||
console.error(
|
||||
chalk.red(
|
||||
'\nDocusaurus user: you probably have this known error due to using a monorepo/workspace.\nWe have a workaround for you, check https://github.com/facebook/docusaurus/issues/3515\n',
|
||||
),
|
||||
);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue