mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(nuxt): components auto-import for JSX (#22330)
This commit is contained in:
parent
694f13b18f
commit
e3437c67d6
@ -31,7 +31,7 @@ export const loaderPlugin = createUnplugin((options: LoaderOptions) => {
|
|||||||
if (include.some(pattern => pattern.test(id))) {
|
if (include.some(pattern => pattern.test(id))) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return isVue(id, { type: ['template', 'script'] })
|
return isVue(id, { type: ['template', 'script'] }) || !!id.match(/\.[tj]sx$/)
|
||||||
},
|
},
|
||||||
transform (code) {
|
transform (code) {
|
||||||
const components = options.getComponents()
|
const components = options.getComponents()
|
||||||
|
@ -129,11 +129,11 @@ export default defineNuxtModule<ComponentsOptions>({
|
|||||||
const unpluginServer = createTransformPlugin(nuxt, getComponents, 'server')
|
const unpluginServer = createTransformPlugin(nuxt, getComponents, 'server')
|
||||||
const unpluginClient = createTransformPlugin(nuxt, getComponents, 'client')
|
const unpluginClient = createTransformPlugin(nuxt, getComponents, 'client')
|
||||||
|
|
||||||
addVitePlugin(unpluginServer.vite(), { server: true, client: false })
|
addVitePlugin(() => unpluginServer.vite(), { server: true, client: false })
|
||||||
addVitePlugin(unpluginClient.vite(), { server: false, client: true })
|
addVitePlugin(() => unpluginClient.vite(), { server: false, client: true })
|
||||||
|
|
||||||
addWebpackPlugin(unpluginServer.webpack(), { server: true, client: false })
|
addWebpackPlugin(() => unpluginServer.webpack(), { server: true, client: false })
|
||||||
addWebpackPlugin(unpluginClient.webpack(), { server: false, client: true })
|
addWebpackPlugin(() => unpluginClient.webpack(), { server: false, client: true })
|
||||||
|
|
||||||
// Do not prefetch global components chunks
|
// Do not prefetch global components chunks
|
||||||
nuxt.hook('build:manifest', (manifest) => {
|
nuxt.hook('build:manifest', (manifest) => {
|
||||||
|
@ -105,6 +105,7 @@ describe('pages', () => {
|
|||||||
// should import JSX/TSX components with custom elements
|
// should import JSX/TSX components with custom elements
|
||||||
expect(html).toContain('TSX component')
|
expect(html).toContain('TSX component')
|
||||||
expect(html).toContain('<custom-component>custom</custom-component>')
|
expect(html).toContain('<custom-component>custom</custom-component>')
|
||||||
|
expect(html).toContain('Sugar Counter 12 x 2 = 24')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('respects aliases in page metadata', async () => {
|
it('respects aliases in page metadata', async () => {
|
||||||
|
1
test/fixtures/basic/components/Tsx.tsx
vendored
1
test/fixtures/basic/components/Tsx.tsx
vendored
@ -3,6 +3,7 @@ export default defineComponent({
|
|||||||
return <div>
|
return <div>
|
||||||
TSX component
|
TSX component
|
||||||
<custom-component>custom</custom-component>
|
<custom-component>custom</custom-component>
|
||||||
|
<SugarCounter multiplier={2} />
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user