Skip to content

Commit

Permalink
Expose Babel config for @astro/react. (#10675)
Browse files Browse the repository at this point in the history
  • Loading branch information
fightingcat authored Apr 4, 2024
1 parent e2a780a commit 14f1d49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-wombats-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/react": minor
---

Expose Babel config for @astro/react.
8 changes: 5 additions & 3 deletions packages/integrations/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { AstroIntegration } from 'astro';
import { version as ReactVersion } from 'react-dom';
import type * as vite from 'vite';

export type ReactIntegrationOptions = Pick<ViteReactPluginOptions, 'include' | 'exclude'> & {
export type ReactIntegrationOptions = Pick<ViteReactPluginOptions, 'include' | 'exclude' | 'babel'> & {
experimentalReactChildren?: boolean;
};

Expand Down Expand Up @@ -46,6 +46,7 @@ function optionsPlugin(experimentalReactChildren: boolean): vite.Plugin {
function getViteConfiguration({
include,
exclude,
babel,
experimentalReactChildren,
}: ReactIntegrationOptions = {}) {
return {
Expand All @@ -65,7 +66,7 @@ function getViteConfiguration({
: '@astrojs/react/server-v17.js',
],
},
plugins: [react({ include, exclude }), optionsPlugin(!!experimentalReactChildren)],
plugins: [react({ include, exclude, babel }), optionsPlugin(!!experimentalReactChildren)],
resolve: {
dedupe: ['react', 'react-dom', 'react-dom/server'],
},
Expand All @@ -89,6 +90,7 @@ function getViteConfiguration({
export default function ({
include,
exclude,
babel,
experimentalReactChildren,
}: ReactIntegrationOptions = {}): AstroIntegration {
return {
Expand All @@ -97,7 +99,7 @@ export default function ({
'astro:config:setup': ({ command, addRenderer, updateConfig, injectScript }) => {
addRenderer(getRenderer());
updateConfig({
vite: getViteConfiguration({ include, exclude, experimentalReactChildren }),
vite: getViteConfiguration({ include, exclude, babel, experimentalReactChildren }),
});
if (command === 'dev') {
const preamble = FAST_REFRESH_PREAMBLE.replace(`__BASE__`, '/');
Expand Down

0 comments on commit 14f1d49

Please sign in to comment.