Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

fix: register the composition api in a template file #433

Merged
merged 6 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/entrypoint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
import Vue from 'vue'
import CompositionApi from '@vue/composition-api'

Vue.use(CompositionApi)

export * from './composables'
export * from './vue'
22 changes: 17 additions & 5 deletions src/module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
isFullStatic,
isUrl,
resolveCoreJsVersion,
resolveRelativePath,
} from './utils'
import { compositionApiPlugin } from './vite'
import { registerBabelPlugin } from './babel'
Expand Down Expand Up @@ -44,20 +45,31 @@ const compositionApiModule: Module<never> = function compositionApiModule() {

nuxtOptions.alias['@nuxtjs/composition-api'] = entryFile

// Transpile Composition API for treeshaking (and de-duping)
// Define @vue/composition-api resolution to prevent issues with registrations

nuxtOptions.alias['@vue/composition-api'] = this.nuxt.resolver.resolveModule(
'@vue/composition-api'
)

// Transpile the Nuxt Composition API to force alias resolution
// TODO: remove this when we stop shadowing module

nuxtOptions.build.transpile = nuxtOptions.build.transpile || []
nuxtOptions.build.transpile.push('@nuxtjs/composition-api')

if (!nuxtOptions.dev) {
nuxtOptions.build.transpile.push('@vue/composition-api')
}
// Register the Vue Composition API before any other layouts

this.addLayout(resolveRelativePath('./templates/layout'), '0')

// If we're using nuxt-vite, register vite plugin & inject configuration

this.nuxt.hook('vite:extend', (ctx: any) => {
ctx.config.plugins.push(compositionApiPlugin())
ctx.config.optimizeDeps.exclude.push('@vue/composition-api')
ctx.config.resolve.alias[
'@vue/composition-api'
] = this.nuxt.resolver.resolveModule(
'@vue/composition-api/dist/vue-composition-api.esm.js'
)
// Fake alias to prevent shadowing actual node_module
ctx.config.resolve.alias['~nuxtjs-composition-api'] = entryFile
})
Expand Down
10 changes: 10 additions & 0 deletions src/templates/layout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Vue from 'vue'
import CompositionApi from '@vue/composition-api'

Vue.use(CompositionApi)

export default {
render() {
return null
}
}