Allow parent plugins to declare what pluginOptions fields core should treat as subplugins #34698
Unanswered
pieh
asked this question in
Ideas / Feature Requests
Replies: 3 comments
-
added option c) that would encapsulate all pluginOptions related task in 1 API hook |
Beta Was this translation helpful? Give feedback.
0 replies
-
Related issues: |
Beta Was this translation helpful? Give feedback.
0 replies
-
It would also be beneficial if gatsby-plugin-mdx and gatsby-transformer-remark supported the same plugins. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
plugins
field in pluginOptions is currently pretty special:gatsby/packages/gatsby/src/bootstrap/load-plugins/load.js
Lines 142 to 150 in 9b2d51b
We treat this as a way to define subplugins (mostly
gatsby-transformer-remark
being parent plugin andgatsby-remark-*
being subplugins).This works ok if there is single kind of plugins, or if different kind of subplugins have named exports so parent plugin know which to execute in various scenarios. The "issues" start happening when some plugin want to make use of plugins that were not created specifically for Gatsby. Example of this would be
gatsby-plugin-mdx
that makes use of 3 kinds of plugins (gatsbyRemarkPlugins
,remarkPlugins
andrehypePlugins
) - because remark and rehype plugins are not created with Gatsby being only consumer,gatsby-plugin-mdx
can't dictate contract between parent plugin and subplugins in this case (for example using named exports).In this case
gatsby-plugin-mdx
needs to have 3 different list of 3 different kinds of subplugins, but right now they don't get special handling and so there are problems: traditional way of declaring plugins is to use plugin name that gatsby core resolves to absolute path and then parent plugin can require it (there are also issues there - see #21589). This path is skipped forgatsby-plugin-mdx
and in cases where yarn/npm will not hoist subplugins (they don't end up in rootnode_modules
and instead they are nested somewhere), thengatsby-plugin-mdx
can't import them and that result in:Module not found
errors that user can't recover from.Example design of API
To solve the problem we need a way for
gatsby-plugin-mdx
to:a) either declare that
gatsbyRemarkPlugins
,remarkPlugins
andrehypePlugins
should be treated as sub plugins (so core can resolve paths). For example:b) or provide helper utility to do that on arbitrary input (the helper function would need to be scoped to each plugin instance or to gatsby-config that declared group of plugins:
(note - just resolving the path will not fix issue with not running
gatsby-x
files APIs, so probably this is bad idea)c) this could also be part of #16697, so the hypothetical
onPluginOptions
API isn't meant only for configuration merges, but would allowpluginOptions
related tasks (including declaring subPlugins)---edit:
On top of not being able to resolve module - we also are not running those subplugins
gatsby-x
files APIs (for example this remark subplugin implements gatsby-browser - https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-remark-images/src/gatsby-browser.js which either doesn't get used right now orgatsby-plugin-mdx
need to have hacky support for by reimplementing core API runner).Beta Was this translation helpful? Give feedback.
All reactions