summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/src
diff options
context:
space:
mode:
authorGravatar Bjorn Lu <bjornlu.dev@gmail.com> 2023-07-31 21:51:37 +0800
committerGravatar Emanuele Stoppa <my.burning@gmail.com> 2023-08-08 11:02:00 +0100
commit84af8ed9d1e6401c6ebc9c60fe8cddb44d5044b0 (patch)
treecd56a48dac47e94c8986ab4cda47adb35a318b80 /packages/integrations/mdx/src
parente20427050746870240bca0e0ffacb6507151a1ea (diff)
downloadastro-84af8ed9d1e6401c6ebc9c60fe8cddb44d5044b0.tar.gz
astro-84af8ed9d1e6401c6ebc9c60fe8cddb44d5044b0.tar.zst
astro-84af8ed9d1e6401c6ebc9c60fe8cddb44d5044b0.zip
Move MDX plugin re-ordering hack to MDX integration (#7872)
Diffstat (limited to 'packages/integrations/mdx/src')
-rw-r--r--packages/integrations/mdx/src/index.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts
index 1d0320213..4d64a84d7 100644
--- a/packages/integrations/mdx/src/index.ts
+++ b/packages/integrations/mdx/src/index.ts
@@ -95,6 +95,21 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
enforce: 'pre',
configResolved(resolved) {
importMetaEnv = { ...importMetaEnv, ...resolved.env };
+
+ // HACK: move ourselves before Astro's JSX plugin to transform things in the right order
+ const jsxPluginIndex = resolved.plugins.findIndex((p) => p.name === 'astro:jsx');
+ if (jsxPluginIndex !== -1) {
+ const myPluginIndex = resolved.plugins.findIndex(
+ (p) => p.name === '@mdx-js/rollup'
+ );
+ if (myPluginIndex !== -1) {
+ const myPlugin = resolved.plugins[myPluginIndex];
+ // @ts-ignore-error ignore readonly annotation
+ resolved.plugins.splice(myPluginIndex, 1);
+ // @ts-ignore-error ignore readonly annotation
+ resolved.plugins.splice(jsxPluginIndex, 0, myPlugin);
+ }
+ }
},
// Override transform to alter code before MDX compilation
// ex. inject layouts