2021-09-27 12:49:36 +00:00
|
|
|
import { useNuxt, addPluginTemplate, addPlugin } from '@nuxt/kit'
|
|
|
|
import { resolve } from 'pathe'
|
2021-09-22 15:34:11 +00:00
|
|
|
import { distDir } from './dirs'
|
|
|
|
|
|
|
|
export function setupCAPIBridge (_options: any) {
|
|
|
|
const nuxt = useNuxt()
|
|
|
|
|
|
|
|
// Error if `@nuxtjs/composition-api` is added
|
|
|
|
if (nuxt.options.buildModules.find(m => m === '@nuxtjs/composition-api' || m === '@nuxtjs/composition-api/module')) {
|
|
|
|
throw new Error('Please remove `@nuxtjs/composition-api` from `buildModules` to avoid conflict with bridge.')
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add composition-api support
|
|
|
|
nuxt.options.alias['@vue/composition-api'] = require.resolve('@vue/composition-api/dist/vue-composition-api.mjs')
|
|
|
|
const capiPluginPath = resolve(distDir, 'runtime/capi.plugin.mjs')
|
|
|
|
addPluginTemplate({ filename: 'capi.plugin.mjs', src: capiPluginPath })
|
2021-09-25 08:24:37 +00:00
|
|
|
|
|
|
|
// Add support for useNuxtApp
|
|
|
|
addPlugin(resolve(distDir, 'runtime/app.plugin.mjs'))
|
|
|
|
|
|
|
|
// Register Composition API before loading the rest of app
|
2021-09-22 15:34:11 +00:00
|
|
|
nuxt.hook('webpack:config', (configs) => {
|
|
|
|
// @ts-ignore
|
|
|
|
configs.forEach(config => config.entry.app.unshift(capiPluginPath))
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO: Add @nuxtjs/composition-api shims
|
|
|
|
}
|