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

fix: change isTSX option to opt-in #1064

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/bridge/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default defineNuxtModule({
})
}
if (opts.typescript) {
await setupTypescript()
await setupTypescript({ isTSX: typeof opts.typescript === 'object' && opts.typescript.isTSX })

// support generating tsconfig by `nuxt dev` (for nuxt 2)
if (!opts.nitro) {
Expand Down
8 changes: 6 additions & 2 deletions packages/bridge/src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { extendWebpackConfig, useNuxt } from '@nuxt/kit'
const extensions = ['ts', 'tsx', 'cts', 'mts']
const typescriptRE = /\.[cm]?tsx?$/

export function setupTypescript () {
type SetupTypescriptOptions = {
isTSX: boolean;
}

export function setupTypescript ({ isTSX }: SetupTypescriptOptions) {
const nuxt = useNuxt()

nuxt.options.extensions.push(...extensions)
Expand All @@ -21,7 +25,7 @@ export function setupTypescript () {
nuxt.options.build.babel.plugins.unshift(
_require.resolve('@babel/plugin-proposal-optional-chaining'),
_require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'),
[_require.resolve('@babel/plugin-transform-typescript'), { isTSX: true }]
[_require.resolve('@babel/plugin-transform-typescript'), { isTSX }]
)

extendWebpackConfig((config) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/bridge/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export interface BridgeConfig {
compatibility: boolean
postcss8: boolean
resolve: boolean
typescript: boolean
typescript: boolean | {
isTSX?: boolean
}
meta: boolean | null
macros: false | {
pageMeta: boolean
Expand Down
4 changes: 3 additions & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const bridgeConfig = {
nitroGenerator: process.env.TEST_NITRO_GENERATOR !== 'false',
imports: process.env.TEST_IMPORTS !== 'false',
meta: process.env.TEST_META !== 'false',
typescript: process.env.TEST_TYPESCRIPT !== 'false',
typescript: {
isTSX: true
},
macros: {
pageMeta: true
}
Expand Down