From 6cdb046cac5cc585a241a537f820530250a06542 Mon Sep 17 00:00:00 2001 From: wattanx Date: Sat, 13 Jan 2024 20:55:50 +0900 Subject: [PATCH] fix: change tsx to opt-in --- packages/bridge/src/module.ts | 2 +- packages/bridge/src/typescript.ts | 8 ++++++-- packages/bridge/types.d.ts | 4 +++- playground/nuxt.config.ts | 4 +++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/bridge/src/module.ts b/packages/bridge/src/module.ts index c8748a2e..6a328025 100644 --- a/packages/bridge/src/module.ts +++ b/packages/bridge/src/module.ts @@ -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) { diff --git a/packages/bridge/src/typescript.ts b/packages/bridge/src/typescript.ts index ad2972fc..7327416a 100644 --- a/packages/bridge/src/typescript.ts +++ b/packages/bridge/src/typescript.ts @@ -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) @@ -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) => { diff --git a/packages/bridge/types.d.ts b/packages/bridge/types.d.ts index bf710761..08b3f678 100644 --- a/packages/bridge/types.d.ts +++ b/packages/bridge/types.d.ts @@ -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 diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index d55a3b7b..e9305c5b 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -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 }