Open PuruVJ opened 1 year ago
hmm... out of scope for now. May be supported in future. A new addon is needed for https://github.com/unjs/unimport
with import
import { Fragment } from "astro/jsx-runtime";
export const frontmatter = {};
export function getHeadings() {
return [];
}
import Code from "../components/Code.svelte";
import { jsx as _jsx } from "astro/jsx-runtime";
function _createMdxContent(props) {
return _jsx(Code, {});
}
try to use auto-import
import { Fragment } from "astro/jsx-runtime";
import { jsx as _jsx } from "astro/jsx-runtime";
export const frontmatter = {};
export function getHeadings() {
return [];
}
function _createMdxContent(props) {
const {
Code
} = props.components || {};
if (!Code) _missingMdxReference("Code", true);
return _jsx(Code, {});
}
Can I add this to my own code? If yes, where?
this is not the addon source. It's the transform original code from you MDX file.
import { Fragment } from "astro/jsx-runtime";
export const frontmatter = {};
export function getHeadings() {
return [];
}
import Code from "../components/Code.svelte";
import { jsx as _jsx } from "astro/jsx-runtime";
function _createMdxContent(props) {
return _jsx(Code, {});
}
function MDXContent(props = {}) {
const {
wrapper: MDXLayout
} = props.components || {};
return MDXLayout ? _jsx(MDXLayout, {
...props,
children: _jsx(_createMdxContent, {
...props
})
}) : _createMdxContent(props);
}
export default MDXContent;
__astro_tag_component__(getHeadings, "astro:jsx");
__astro_tag_component__(MDXContent, "astro:jsx");
MDXContent[Symbol.for('astro.needsHeadRendering')] = !Boolean(frontmatter.layout);
export const url = "";
export const file = "C:/Users/.../Desktop/ts/src/pages/index.mdx";
export function rawContent() { throw new Error("MDX does not support rawContent()! If you need to read the Markdown contents to calculate values (ex. reading time), we suggest injecting frontmatter via remark plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins") };
export function compiledContent() { throw new Error("MDX does not support compiledContent()! If you need to read the HTML contents to
calculate values (ex. reading time), we suggest injecting frontmatter via rehype plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins") };
export const Content = MDXContent;
if (import.meta.hot) {
import.meta.hot.decline();
}
since it does not contain any keyword like 'import' so the auto-import fails.
you need to write an addon to parsing MDX file to identify imports. Like https://github.com/unjs/unimport/blob/main/src/addons/vue-template.ts
This is for vue template to find all _ctx.
as import target.
In your case, it will be more complex.
because I find the _createMdxContent
is quite different with/without import.
you need to write an addon to parsing MDX file to identify imports. Like https://github.com/unjs/unimport/blob/main/src/addons/vue-template.ts
This is for vue template to find all
_ctx.
as import target.In your case, it will be more complex. because I find the
_createMdxContent
is quite different with/without import.
There is a working implementation(although in a different context) that might help: https://github.com/delucis/astro-auto-import
Describe the bug
This package doesn't work with Astro+MDX integration.
I defined the proper component path and exports in the config. When I Use the auto imports in .astro files or .svelte files, it works well. But in .mdx file, it completely fails.
In reproduction, if you go to
/some-page
route, it works there. But on/
page which is a.mdx
file, it doesn'tReproduction
https://stackblitz.com/edit/github-vsez61?file=package.json,astro.config.mjs,src%2Fpages%2Findex.mdx,src%2Fpages%2Fsome-page.astro&on=stackblitz
System Info
Used Package Manager
pnpm
Validations