Question about bundleMDX (files, globals, cwd)
See original GitHub issueHi,
thanks for building this project!
mdx-bundler
version: ^5.2.1node
version: 15.14.0npm
version: 7.15.0
I am currently working on building this blog: https://github.com/chrislicodes/personal-blog.
The function to bundle the MDX looks like this:
export const prepareMDX = async (directoryName: string) => {
if (process.platform === "win32") {
process.env.ESBUILD_BINARY_PATH = path.join(
process.cwd(),
"node_modules",
"esbuild",
"esbuild.exe"
);
} else {
process.env.ESBUILD_BINARY_PATH = path.join(
process.cwd(),
"node_modules",
"esbuild",
"bin",
"esbuild"
);
}
const directory = path.join(POSTS_PATH, "/", directoryName);
const source = getSourceOfFile(directory + "/index.mdx");
// const files = await getComponents(directoryName);
const { code, frontmatter } = await bundleMDX(source, {
// files,
cwd: directory,
xdmOptions: (options) => {
options.remarkPlugins = [
...(options.remarkPlugins ?? []),
remarkMdxImages,
];
return options;
},
esbuildOptions: (options) => {
options.outdir = path.join(process.cwd(), "/public/img");
options.loader = {
...options.loader,
".png": "file",
".jpg": "file",
".gif": "file",
".mp3": "file",
};
options.publicPath = "/img/";
options.write = true;
return options;
},
});
return { frontmatter, code };
};
In this post, I am importing a component using React Three Fiber:
https://github.com/chrislicodes/personal-blog/blob/main/src/_posts/three-js-post/index.mdx
Using it this way leads to multiple instances of THREE being imported. The multiple imports should be fixed using the “globals” parameter, or would that only apply I import the libraries in the .mdx file directly?
My questions:
- With passing the “cwd” parameter, the imports in a .mdx file can be resolved - in which scenarios would I have to pass/use the “files” parameter?
- Can I fix the multiple THREE.js instances with the “globals” parameter, or would that only be needed if I import a library directly in an MDX file?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Create feature-rich markdown pages in next.js application
Step-by-step tutorial on creating feature-rich markdown pages in next.js application using mdx-bundler.
Read more >cannot access 'fs' before initialization - You.com | The AI ...
I already red all anwsers talking about this problem but I still can't find ... access function before initialization in file that imports...
Read more >MDX Bundler with Next.JS - Adam Laycock
MDX Bundler's server side component is bundleMDX . This takes your mdx ... It takes the source MDX and the imported files as...
Read more >How I built the new notjust.dev platform with NextJS
The data for the blog posts is written in markdown (.md) files. ... const { code, frontmatter } = await bundleMDX(fileContents, {. cwd: ......
Read more >output images corrupt when using mdx-bundler + remark-mdx ...
I am using a combination of mdx-bundler to convert the MDX files into ... await bundleMDX({ source: indexFile.content, files: filesObject, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@chrislicodes Turns out you need to configure esbuild named-exports.
https://www.npmjs.com/package/@fal-works/esbuild-plugin-global-externals
Everything worked as expected thanks to the previous comment