mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-04 20:02:54 +02:00
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:
parent
bb55586c20
commit
949a72e6a5
3 changed files with 61 additions and 45 deletions
|
@ -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` ㄟ(▔,▔)ㄏ
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue