Unverified Commit a4692d40 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add support for jsxImportSource in tsconfig/jsconfig (#31358)

parent 06f3d398
......@@ -9,6 +9,7 @@ function getBaseSWCOptions({
styledComponents,
paths,
baseUrl,
importSource,
}) {
const isTSFile = filename.endsWith('.ts')
const isTypeScript = isTSFile || filename.endsWith('.tsx')
......@@ -30,6 +31,7 @@ function getBaseSWCOptions({
transform: {
react: {
importSource: importSource || 'react',
runtime: 'automatic',
pragma: 'React.createElement',
pragmaFrag: 'React.Fragment',
......@@ -107,6 +109,7 @@ export function getLoaderSWCOptions({
isPageFile,
hasReactRefresh,
styledComponents,
importSource,
}) {
let baseOptions = getBaseSWCOptions({
filename,
......@@ -114,6 +117,7 @@ export function getLoaderSWCOptions({
globalWindow: !isServer,
hasReactRefresh,
styledComponents,
importSource,
})
const isNextDist = nextDistPath.test(filename)
......
......@@ -321,6 +321,10 @@ export default async function getBaseWebpackConfig(
runWebpackSpan: Span
}
): Promise<webpack.Configuration> {
const { useTypeScript, jsConfig, resolvedBaseUrl } = await loadJsConfig(
dir,
config
)
const supportedBrowsers = await getSupportedBrowsers(dir, dev)
const hasRewrites =
rewrites.beforeFiles.length > 0 ||
......@@ -438,6 +442,7 @@ export default async function getBaseWebpackConfig(
pagesDir,
hasReactRefresh: !isMiddleware && hasReactRefresh,
styledComponents: config.experimental.styledComponents,
importSource: jsConfig?.compilerOptions?.jsxImportSource,
},
}
: {
......@@ -521,11 +526,6 @@ export default async function getBaseWebpackConfig(
} as ClientEntries)
: undefined
const { useTypeScript, jsConfig, resolvedBaseUrl } = await loadJsConfig(
dir,
config
)
function getReactProfilingInProduction() {
if (reactProductionProfiling) {
return {
......
......@@ -35,8 +35,13 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {
let loaderOptions = this.getOptions() || {}
const { isServer, pagesDir, hasReactRefresh, styledComponents } =
loaderOptions
const {
isServer,
pagesDir,
hasReactRefresh,
styledComponents,
importSource,
} = loaderOptions
const isPageFile = filename.startsWith(pagesDir)
const swcOptions = getLoaderSWCOptions({
......@@ -47,6 +52,7 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {
development: this.mode === 'development',
hasReactRefresh,
styledComponents,
importSource,
})
const programmaticOptions = {
......
import { join } from 'path'
import webdriver from 'next-webdriver'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
describe('theme-ui SWC option', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {
'jsconfig.json': new FileRef(join(__dirname, 'theme-ui/jsconfig.json')),
pages: new FileRef(join(__dirname, 'theme-ui/pages')),
'theme.js': new FileRef(join(__dirname, 'theme-ui/theme.js')),
},
dependencies: {
'theme-ui': '0.12.0',
},
})
})
afterAll(() => next.destroy())
it('should have theme provided styling', async () => {
let browser
try {
browser = await webdriver(next.appPort, '/')
const color = await browser.elementByCss('#hello').getComputedCss('color')
expect(color).toBe('rgb(51, 51, 238)')
} finally {
if (browser) {
await browser.close()
}
}
})
})
{
"compilerOptions": {
"jsxImportSource": "theme-ui"
}
}
// basic usage
import { ThemeProvider } from 'theme-ui'
import theme from '../theme'
function MyApp({ Component, pageProps }) {
return (
<ThemeProvider theme={theme}>
<Component {...pageProps} />
</ThemeProvider>
)
}
export default MyApp
export default function Home() {
return (
<div
id="hello"
sx={{
fontWeight: 'bold',
fontSize: 4, // picks up value from `theme.fontSizes[4]`
color: 'primary', // picks up value from `theme.colors.primary`
}}
>
Hello
</div>
)
}
// example theme.js
export default {
fonts: {
body: 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif',
heading: '"Avenir Next", sans-serif',
monospace: 'Menlo, monospace',
},
colors: {
text: '#000',
background: '#fff',
primary: '#33e',
},
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment