@@ -498,7 +498,7 @@ import {remarkMdxImages} from 'remark-mdx-images'
498498
499499const {code } = await bundleMDX (mdxSource, {
500500 cwd: ' /users/you/site/_content/pages' ,
501- xdmOptions : ( vFile , options ) => {
501+ xdmOptions : options => {
502502 options .remarkPlugins = [remarkMdxImages]
503503
504504 return options
@@ -519,24 +519,30 @@ The `file` loader requires a little more configuration to get working. With the
519519be set to write files and needs to know where to put them plus the url of the
520520folder to be used in image sources.
521521
522+ > Each call to ` bundleMDX ` is isloated from the others. If you set the directory
523+ > the same for everything ` bundleMDX ` will overwrite images without warning. As
524+ > a result each _ bundle_ needs its own output directory.
525+
522526``` js
527+ // For the file `_content/pages/about.mdx`
528+
523529const {code } = await bundleMDX (mdxSource, {
524530 cwd: ' /users/you/site/_content/pages' ,
525- xdmOptions : ( vFile , options ) => {
531+ xdmOptions : options => {
526532 options .remarkPlugins = [remarkMdxImages]
527533
528534 return options
529535 },
530536 esbuildOptions : options => {
531- // Set the `outdir` to your public directory .
532- options .outdir = ' /users/you/site/public/img'
537+ // Set the `outdir` to a public location for this bundle .
538+ options .outdir = ' /users/you/site/public/img/about '
533539 options .loader = {
534540 ... options .loader ,
535541 // Tell esbuild to use the `file` loader for pngs
536542 ' .png' : ' file' ,
537543 }
538- // Set the public path to /img/ so image sources start /img/
539- options .publicPath = ' /img/'
544+ // Set the public path to /img/about
545+ options .publicPath = ' /img/about '
540546
541547 // Set write to true so that esbuild will output the files.
542548 options .write = true
@@ -546,6 +552,23 @@ const {code} = await bundleMDX(mdxSource, {
546552})
547553```
548554
555+ ### Replacing the entry point
556+
557+ If your MDX file is on your disk you can save some time and code by having
558+ ` esbuild ` read the file for you. To do this you can override the ` entryPoints `
559+ settings in ` esbuildOptions ` with the path to your mdx source.
560+
561+ ``` js
562+ const {code , frontmatter } = await bundleMDX (' ' , {
563+ cwd: ' /users/you/site/_content/pages' ,
564+ esbuildOptions : options => {
565+ options .entryPoints = [' /users/you/site/_content/pages/file.mdx' ]
566+
567+ return options
568+ },
569+ })
570+ ```
571+
549572### Known Issues
550573
551574#### Cloudflare Workers
@@ -647,7 +670,7 @@ Thanks goes to these people ([emoji key][emojis]):
647670 <tr >
648671 <td align="center"><a href="https://kentcdodds.com"><img src="https://avatars.githubusercontent.com/u/1500684?v=3?s=100" width="100px;" alt=""/><br /><sub><b>Kent C. Dodds</b></sub></a><br /><a href="https://github.com/kentcdodds/mdx-bundler/commits?author=kentcdodds" title="Code">💻</a> <a href="https://github.com/kentcdodds/mdx-bundler/commits?author=kentcdodds" title="Documentation">📖</a> <a href="#infra-kentcdodds" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/kentcdodds/mdx-bundler/commits?author=kentcdodds" title="Tests">⚠️</a></td>
649672 <td align="center"><a href="https://github.com/benwis"><img src="https://avatars.githubusercontent.com/u/6953353?v=4?s=100" width="100px;" alt=""/><br /><sub><b>benwis</b></sub></a><br /><a href="https://github.com/kentcdodds/mdx-bundler/issues?q=author%3Abenwis" title="Bug reports">🐛</a> <a href="https://github.com/kentcdodds/mdx-bundler/pulls?q=is%3Apr+reviewed-by%3Abenwis" title="Reviewed Pull Requests">👀</a></td>
650- <td align="center"><a href="https://arcath.net"><img src="https://avatars.githubusercontent.com/u/19609?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Adam Laycock</b></sub></a><br /><a href="https://github.com/kentcdodds/mdx-bundler/commits?author=Arcath" title="Code">💻</a> <a href="https://github.com/kentcdodds/mdx-bundler/commits?author=Arcath" title="Tests">⚠️</a> <a href="#ideas-Arcath" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/kentcdodds/mdx-bundler/pulls?q=is%3Apr+reviewed-by%3AArcath" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/kentcdodds/mdx-bundler/commits?author=Arcath" title="Documentation">📖</a></td>
673+ <td align="center"><a href="https://www. arcath.net"><img src="https://avatars.githubusercontent.com/u/19609?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Adam Laycock</b></sub></a><br /><a href="https://github.com/kentcdodds/mdx-bundler/commits?author=Arcath" title="Code">💻</a> <a href="https://github.com/kentcdodds/mdx-bundler/commits?author=Arcath" title="Tests">⚠️</a> <a href="#ideas-Arcath" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/kentcdodds/mdx-bundler/pulls?q=is%3Apr+reviewed-by%3AArcath" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/kentcdodds/mdx-bundler/commits?author=Arcath" title="Documentation">📖</a></td>
651674 <td align="center"><a href="http://wooorm.com"><img src="https://avatars.githubusercontent.com/u/944406?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Titus</b></sub></a><br /><a href="#ideas-wooorm" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/kentcdodds/mdx-bundler/pulls?q=is%3Apr+reviewed-by%3Awooorm" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/kentcdodds/mdx-bundler/commits?author=wooorm" title="Code">💻</a></td>
652675 <td align="center"><a href="https://github.com/ChristianMurphy"><img src="https://avatars.githubusercontent.com/u/3107513?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Christian Murphy</b></sub></a><br /><a href="#ideas-ChristianMurphy" title="Ideas, Planning, & Feedback">🤔</a></td>
653676 <td align="center"><a href="https://ped.ro"><img src="https://avatars.githubusercontent.com/u/372831?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Pedro Duarte</b></sub></a><br /><a href="https://github.com/kentcdodds/mdx-bundler/commits?author=peduarte" title="Documentation">📖</a></td>
0 commit comments