perf(mdx-loader): cache mdx/remark compiler instances (#4997)

* (mdx-loader) only create mdx compiler once per webpack config

* type fixes

* fix path

* remove assertion

* docs: add missing Tab/TabItem imports

* fixup

Co-authored-by: slorber <lorber.sebastien@gmail.com>
Co-authored-by: Josh-Cena <sidachen2003@gmail.com>
This commit is contained in:
Lenz Weber-Tronic 2022-03-31 09:42:57 +02:00 committed by GitHub
parent bb55586c20
commit 949a72e6a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 45 deletions

View file

@ -6,7 +6,7 @@
*/
import type {Code, Content, Literal} from 'mdast';
import type {Plugin, Transformer} from 'unified';
import type {Plugin} from 'unified';
import type {Node, Parent} from 'unist';
import visit from 'unist-util-visit';
import npmToYarn from 'npm-to-yarn';
@ -61,9 +61,9 @@ const nodeForImport: Literal = {
const plugin: Plugin<[PluginOptions?]> = (options = {}) => {
const {sync = false} = options;
let transformed = false;
let alreadyImported = false;
const transformer: Transformer = (root) => {
return (root) => {
let transformed = false;
let alreadyImported = false;
visit(root, (node: Node) => {
if (isImport(node) && node.value.includes('@theme/Tabs')) {
alreadyImported = true;
@ -87,7 +87,6 @@ const plugin: Plugin<[PluginOptions?]> = (options = {}) => {
(root as Parent).children.unshift(nodeForImport);
}
};
return transformer;
};
// To continue supporting `require('npm2yarn')` without the `.default` ㄟ(▔,▔)ㄏ