I have blog post mdx files. I have a NewsletterSignup component for them that gets put in the mdx files like <NewsletterSignup /> and would like to have all of the mdx files automatically import the necessary component without me having to manually do it. Is this possible? The import statement would look like import NewsletterSignup from "./src/components/NewsletterSignup/NewsletterSignup"
I've tried writing a remark plugin (below), and it adds the import statement to the ast, but Astro throws an error that says "...you likely forgot to import...". If I manually type in the import statement in the mdx file it works just fine.
export default function remarkAddImport(options) {
return (tree) => {
// at the start of every mdx file, import necessary components
tree.children.unshift({
type: "import",
value: `import NewsletterSignup from "./src/components/NewsletterSignup/NewsletterSignup"`,
});
};
}