perf(bridge): allow skipping legacy composition api support (#2388)

This commit is contained in:
Daniel Roe 2021-12-17 09:44:59 +00:00 committed by GitHub
parent 03f9cfa50b
commit daec4323bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 3 deletions

View File

@ -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,

View File

@ -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')

View File

@ -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)

View File

@ -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