-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Allow custom babel config for content plugins #4035
Comments
WorkaroundThis webpack plugin will modify all mdx loaders to use a custom babel config. module.exports = function customWebpackPlugin(context, options) {
return {
name: 'custom-webpack-plugin',
configureWebpack(config, isServer, utils) {
modifyBabelConfigForDocusaurusContentDocsPlugins(config, isServer, utils)
}
}
}
function modifyBabelConfigForDocusaurusContentDocsPlugins(config, isServer, utils) {
const mdxRegex = /(\.mdx?)$/
const matchingRules = config.module.rules.filter(
rule => rule.test.toString() === mdxRegex.toString(),
)
//const {getBabelLoader} = utils
matchingRules.map(rule => {
const babelLoaders = rule.use.filter(use => use.loader.match('babel-loader'))
babelLoaders.map(loader => {
loader.options.configFile = join(process.cwd(), 'babel.config.js')
delete loader.options.presets
delete loader.options.babelrc
})
})
} |
Hi, We already support the babel.config.js file out of the box: You are right that it seems it's not used by the mdx loaders of the content plugins, leading to your custom config not being applied when loading mdx files. Your custom babel config would only work when loading .js/jsx components, not .md/.mdx files. If we add support for the babel config to the mdx loaders, is it good enough for you? Or do you see usecases where the babel config should be different per plugin, or between .js/mdx? As your usecase seems to be using Tailwind with Twin macros (#3994 (comment)), I must say I'm not sure you would be able to use the |
It does seem to work for me, doing something like:
Yep. I mistakenly thought So the custom babel config is useless for much else...but still it does seem to work for mdx. |
Sorry but I'm a bit confused 😅 We have a brand new http://new.docusaurus.io/ to easily create repro cases. If you can show me exactly what I should add support for with a failing sandbox, that would help me implement the missing bits needed |
Ideally I would like to be able to pass in a custom Will look at a repro soon. |
One of the most pressing configs I need actually in a monorepo context is the ability to Here is a dump of my webpack config for my root docs plugin (generated via https://www.npmjs.com/package/webpack-config-dump-plugin). I need to be able to modify the For an example of my monorepo structure see here (#4055 (comment)).
This doesn't seem to be set in the
|
🚀 Feature
Have you read the Contributing Guidelines on issues?
Yes
Motivation
I want to use tailwindcss in my docs/blog/pages.
You can see here the
createMDXLoaderRule
hardcodes the babel loader and doesn't allow configuring thebabelOptions
.Pitch
The easy fix is to add
babelOptions
to the plugin config and pass it through.Issue was identified thanks to: ben-rogerson/twin.macro#125 (comment)
The text was updated successfully, but these errors were encountered: