Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to pass in an unpublished remark plugin as a function to nuxt.config.ts #2834

Open
JessicaSachs opened this issue Nov 5, 2024 · 1 comment
Labels
enhancement New feature or request v2 Relevant for @nuxt/content v2

Comments

@JessicaSachs
Copy link

JessicaSachs commented Nov 5, 2024

Is your feature request related to a problem? Please describe

Currently, developing and testing custom remark plugins locally is unnecessarily complicated due to two main issues:

  1. Module Resolution Conflict: When passing a resolved remark plugin, the module loader bypasses the local version and assumes I have a package installed and tries to resolve it by the key 🙄.

  2. Forced Package Resolution: Even after working around the initial import check, the compiled mdc-imports.mjs file still attempts to resolve plugins via the key specified in the Nuxt Content config, ignoring locally provided implementations.

Technical demonstration of the issue:
Image

Describe the solution you'd like

We need the ability to use local remark plugins without the requirement to:

  • Publish a package
  • Configure package.json resolutions
  • Switch from TypeScript to JavaScript
  • Set up transpilation

Ideal implementation would look like this:

// content-plugins/remark-jess-has-a-plugin.ts
export default function myPlugin() {
}

// Nuxt Config
import remarkPublicThingyPlugin from 'remark-public-thingy'
import remarkJessHasAPlugin from './content-plugins/remark-jess-has-a-plugin'

export default defineNuxtConfig({
  content: {
    markdown: {
      remarkPlugins: {
        'remark-public-thingy': remarkPublicThingyPlugin,
        'remark-jess-has-a-plugin': myPlugin,
      }
    }
  }
})

Additional context

This feature would greatly improve the developer experience for:

  • Rapid prototyping of remark plugins
  • Testing modifications before publishing
  • Local-only customizations
@JessicaSachs JessicaSachs added the enhancement New feature or request label Nov 5, 2024
@JessicaSachs JessicaSachs changed the title Ability to pass in an unpublish remark plugin as a function to nuxt.config.ts Ability to pass in an unpublished remark plugin as a function to nuxt.config.ts Nov 5, 2024
@farnabaz
Copy link
Member

farnabaz commented Nov 5, 2024

It it not possible to pass the plugin function directly in config. However, the MDC module supports the src field to define the plugin path.

Try passing your custom plugin into mdc.remarkPlugins with src.

export default defineNuxtConfig({
  mdc: {
    remarkPlugins: {
      'remark-jess-has-a-plugin': {
        src: resolve(__dirname, './content-plugins/remark-jess-has-a-plugin')
      }
    }
  }
})

@farnabaz farnabaz added the v2 Relevant for @nuxt/content v2 label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v2 Relevant for @nuxt/content v2
Projects
None yet
Development

No branches or pull requests

2 participants