facebook / facebook/docusaurus

Allow custom babel config for content plugins

Ouverte
#4,035 6 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
feature
Langage dominant
TypeScript
Étoiles
66.2k
Forks
10k
Merge moyen
1 j 3 h
PR mergées (30 j)
52

Description

## 🚀 Feature

### Have you read the [Contributing Guidelines on issues](https://github.com/facebook/docusaurus/blob/master/CONTRIBUTING.md#reporting-new-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 the `babelOptions`.

```
function createMDXLoaderRule(): RuleSetRule {
return {
test: /(\.mdx?)$/,
include: flatten(versionsMetadata.map(getDocsDirPaths))
// Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
.map(addTrailingPathSeparator),
use: compact([
getCacheLoader(isServer),
getBabelLoader(isServer),
{
```

```
export function getBabelLoader(
isServer: boolean,
babelOptions?: TransformOptions | string,
): Loader {
return {
loader: require.resolve('babel-loader'),
options: getBabelOptions({isServer, babelOptions}),
};
}
```

```
export function getBabelOptions({
isServer,
babelOptions,
}: {
isServer?: boolean;
babelOptions?: TransformOptions | string;
} = {}): TransformOptions {
if (typeof babelOptions === 'string') {
return {
babelrc: false,
configFile: babelOptions,
caller: {name: isServer ? 'server' : 'client'},
};
} else {
return Object.assign(
babelOptions ?? {presets: [require.resolve('../babel/preset')]},
{
babelrc: false,
configFile: false,
caller: {name: isServer ? 'server' : 'client'},
},
);
}
}
```

## Pitch

The easy fix is to add `babelOptions` to the plugin config and pass it through.

---

Issue was identified thanks to: https://github.com/ben-rogerson/twin.macro/issues/125#issuecomment-677694758

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.