mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Expose Babel config for @astro/react. (#10675)
This commit is contained in:
parent
e2a780a46d
commit
14f1d49a10
2 changed files with 10 additions and 3 deletions
5
.changeset/tall-wombats-clap.md
Normal file
5
.changeset/tall-wombats-clap.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"@astrojs/react": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Expose Babel config for @astro/react.
|
|
@ -3,7 +3,7 @@ import type { AstroIntegration } from 'astro';
|
||||||
import { version as ReactVersion } from 'react-dom';
|
import { version as ReactVersion } from 'react-dom';
|
||||||
import type * as vite from 'vite';
|
import type * as vite from 'vite';
|
||||||
|
|
||||||
export type ReactIntegrationOptions = Pick<ViteReactPluginOptions, 'include' | 'exclude'> & {
|
export type ReactIntegrationOptions = Pick<ViteReactPluginOptions, 'include' | 'exclude' | 'babel'> & {
|
||||||
experimentalReactChildren?: boolean;
|
experimentalReactChildren?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ function optionsPlugin(experimentalReactChildren: boolean): vite.Plugin {
|
||||||
function getViteConfiguration({
|
function getViteConfiguration({
|
||||||
include,
|
include,
|
||||||
exclude,
|
exclude,
|
||||||
|
babel,
|
||||||
experimentalReactChildren,
|
experimentalReactChildren,
|
||||||
}: ReactIntegrationOptions = {}) {
|
}: ReactIntegrationOptions = {}) {
|
||||||
return {
|
return {
|
||||||
|
@ -65,7 +66,7 @@ function getViteConfiguration({
|
||||||
: '@astrojs/react/server-v17.js',
|
: '@astrojs/react/server-v17.js',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
plugins: [react({ include, exclude }), optionsPlugin(!!experimentalReactChildren)],
|
plugins: [react({ include, exclude, babel }), optionsPlugin(!!experimentalReactChildren)],
|
||||||
resolve: {
|
resolve: {
|
||||||
dedupe: ['react', 'react-dom', 'react-dom/server'],
|
dedupe: ['react', 'react-dom', 'react-dom/server'],
|
||||||
},
|
},
|
||||||
|
@ -89,6 +90,7 @@ function getViteConfiguration({
|
||||||
export default function ({
|
export default function ({
|
||||||
include,
|
include,
|
||||||
exclude,
|
exclude,
|
||||||
|
babel,
|
||||||
experimentalReactChildren,
|
experimentalReactChildren,
|
||||||
}: ReactIntegrationOptions = {}): AstroIntegration {
|
}: ReactIntegrationOptions = {}): AstroIntegration {
|
||||||
return {
|
return {
|
||||||
|
@ -97,7 +99,7 @@ export default function ({
|
||||||
'astro:config:setup': ({ command, addRenderer, updateConfig, injectScript }) => {
|
'astro:config:setup': ({ command, addRenderer, updateConfig, injectScript }) => {
|
||||||
addRenderer(getRenderer());
|
addRenderer(getRenderer());
|
||||||
updateConfig({
|
updateConfig({
|
||||||
vite: getViteConfiguration({ include, exclude, experimentalReactChildren }),
|
vite: getViteConfiguration({ include, exclude, babel, experimentalReactChildren }),
|
||||||
});
|
});
|
||||||
if (command === 'dev') {
|
if (command === 'dev') {
|
||||||
const preamble = FAST_REFRESH_PREAMBLE.replace(`__BASE__`, '/');
|
const preamble = FAST_REFRESH_PREAMBLE.replace(`__BASE__`, '/');
|
||||||
|
|
Loading…
Reference in a new issue