mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 09:02:03 +00:00
perf(bridge): allow skipping legacy composition api support (#2388)
This commit is contained in:
parent
03f9cfa50b
commit
daec4323bb
@ -251,6 +251,11 @@ export default defineNuxtConfig({
|
||||
// Disable composition API support
|
||||
// capi: false,
|
||||
|
||||
// ... or just disable legacy composition API support
|
||||
// capi: {
|
||||
// legacy: false
|
||||
// },
|
||||
|
||||
// Do not transpile modules
|
||||
// transpile: false,
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
import { createRequire } from 'module'
|
||||
import { useNuxt, addPlugin, addPluginTemplate, addVitePlugin, addWebpackPlugin } from '@nuxt/kit'
|
||||
import { resolve } from 'pathe'
|
||||
import { BridgeConfig } from '../types'
|
||||
import { distDir } from './dirs'
|
||||
import { KeyPlugin } from './capi-legacy-key-plugin'
|
||||
|
||||
export function setupCAPIBridge (_options: any) {
|
||||
export function setupCAPIBridge (options: Exclude<BridgeConfig['capi'], boolean>) {
|
||||
const nuxt = useNuxt()
|
||||
|
||||
// Error if `@nuxtjs/composition-api` is added
|
||||
@ -36,6 +37,11 @@ export function setupCAPIBridge (_options: any) {
|
||||
configs.forEach(config => config.entry.app.unshift(capiPluginPath))
|
||||
})
|
||||
|
||||
if (options.legacy === false) {
|
||||
// Skip adding `@nuxtjs/composition-api` handlers if legacy support is disabled
|
||||
return
|
||||
}
|
||||
|
||||
// Handle legacy `@nuxtjs/composition-api`
|
||||
nuxt.options.alias['@nuxtjs/composition-api'] = resolve(distDir, 'runtime/capi.legacy.mjs')
|
||||
nuxt.options.build.transpile.push('@nuxtjs/composition-api', '@vue/composition-api')
|
||||
|
@ -42,7 +42,7 @@ export default defineNuxtModule({
|
||||
if (!opts.app) {
|
||||
throw new Error('[bridge] Cannot enable composition-api with app disabled!')
|
||||
}
|
||||
await setupCAPIBridge(opts.capi)
|
||||
await setupCAPIBridge(opts.capi === true ? {} : opts.capi)
|
||||
}
|
||||
if (opts.scriptSetup) {
|
||||
await setupScriptSetup(opts.scriptSetup as ScriptSetupOptions)
|
||||
|
4
packages/bridge/types.d.ts
vendored
4
packages/bridge/types.d.ts
vendored
@ -9,7 +9,9 @@ export interface BridgeConfig {
|
||||
nitro: boolean
|
||||
vite: boolean
|
||||
app: boolean | {}
|
||||
capi: boolean | {}
|
||||
capi: boolean | {
|
||||
legacy?: boolean
|
||||
}
|
||||
scriptSetup: boolean | ScriptSetupOptions
|
||||
autoImports: boolean
|
||||
transpile: boolean
|
||||
|
Loading…
Reference in New Issue
Block a user