Skip to content
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

Emotion SWC Plugin - Allow for jsxImportSource to be configurable #35963

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/next/build/swc/options.js
Expand Up @@ -40,6 +40,7 @@ function getBaseSWCOptions({
const emitDecoratorMetadata = Boolean(
jsConfig?.compilerOptions?.emitDecoratorMetadata
)
const emotionOptions = getEmotionOptions(nextConfig, jsConfig, development)
return {
jsc: {
...(resolvedBaseUrl && paths
Expand All @@ -65,7 +66,7 @@ function getBaseSWCOptions({
decoratorMetadata: emitDecoratorMetadata,
react: {
importSource: nextConfig?.experimental?.emotion
Brooooooklyn marked this conversation as resolved.
Show resolved Hide resolved
? '@emotion/react'
? emotionOptions.jsxImportSource
: jsConfig?.compilerOptions?.jsxImportSource || 'react',
runtime: 'automatic',
pragma: 'React.createElement',
Expand Down Expand Up @@ -104,11 +105,11 @@ function getBaseSWCOptions({
reactRemoveProperties: nextConfig?.compiler?.reactRemoveProperties,
modularizeImports: nextConfig?.experimental?.modularizeImports,
relay: nextConfig?.compiler?.relay,
emotion: getEmotionOptions(nextConfig, development),
emotion: emotionOptions,
}
}

function getEmotionOptions(nextConfig, development) {
function getEmotionOptions(nextConfig, jsConfig, development) {
if (!nextConfig?.experimental?.emotion) {
return null
}
Expand All @@ -126,6 +127,8 @@ function getEmotionOptions(nextConfig, development) {
break
}
return {
jsxImportSource:
jsConfig?.compilerOptions?.jsxImportSource ?? '@emotion/react',
enabled: true,
autoLabel,
labelFormat: nextConfig?.experimental?.emotion?.labelFormat,
Expand Down