mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-01 18:07:22 +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
|
// Disable composition API support
|
||||||
// capi: false,
|
// capi: false,
|
||||||
|
|
||||||
|
// ... or just disable legacy composition API support
|
||||||
|
// capi: {
|
||||||
|
// legacy: false
|
||||||
|
// },
|
||||||
|
|
||||||
// Do not transpile modules
|
// Do not transpile modules
|
||||||
// transpile: false,
|
// transpile: false,
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { createRequire } from 'module'
|
import { createRequire } from 'module'
|
||||||
import { useNuxt, addPlugin, addPluginTemplate, addVitePlugin, addWebpackPlugin } from '@nuxt/kit'
|
import { useNuxt, addPlugin, addPluginTemplate, addVitePlugin, addWebpackPlugin } from '@nuxt/kit'
|
||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
|
import { BridgeConfig } from '../types'
|
||||||
import { distDir } from './dirs'
|
import { distDir } from './dirs'
|
||||||
import { KeyPlugin } from './capi-legacy-key-plugin'
|
import { KeyPlugin } from './capi-legacy-key-plugin'
|
||||||
|
|
||||||
export function setupCAPIBridge (_options: any) {
|
export function setupCAPIBridge (options: Exclude<BridgeConfig['capi'], boolean>) {
|
||||||
const nuxt = useNuxt()
|
const nuxt = useNuxt()
|
||||||
|
|
||||||
// Error if `@nuxtjs/composition-api` is added
|
// Error if `@nuxtjs/composition-api` is added
|
||||||
@ -36,6 +37,11 @@ export function setupCAPIBridge (_options: any) {
|
|||||||
configs.forEach(config => config.entry.app.unshift(capiPluginPath))
|
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`
|
// Handle legacy `@nuxtjs/composition-api`
|
||||||
nuxt.options.alias['@nuxtjs/composition-api'] = resolve(distDir, 'runtime/capi.legacy.mjs')
|
nuxt.options.alias['@nuxtjs/composition-api'] = resolve(distDir, 'runtime/capi.legacy.mjs')
|
||||||
nuxt.options.build.transpile.push('@nuxtjs/composition-api', '@vue/composition-api')
|
nuxt.options.build.transpile.push('@nuxtjs/composition-api', '@vue/composition-api')
|
||||||
|
@ -42,7 +42,7 @@ export default defineNuxtModule({
|
|||||||
if (!opts.app) {
|
if (!opts.app) {
|
||||||
throw new Error('[bridge] Cannot enable composition-api with app disabled!')
|
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) {
|
if (opts.scriptSetup) {
|
||||||
await setupScriptSetup(opts.scriptSetup as ScriptSetupOptions)
|
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
|
nitro: boolean
|
||||||
vite: boolean
|
vite: boolean
|
||||||
app: boolean | {}
|
app: boolean | {}
|
||||||
capi: boolean | {}
|
capi: boolean | {
|
||||||
|
legacy?: boolean
|
||||||
|
}
|
||||||
scriptSetup: boolean | ScriptSetupOptions
|
scriptSetup: boolean | ScriptSetupOptions
|
||||||
autoImports: boolean
|
autoImports: boolean
|
||||||
transpile: boolean
|
transpile: boolean
|
||||||
|
Loading…
Reference in New Issue
Block a user