|
1 | 1 | import type { Module, NuxtOptions } from '@nuxt/types'
|
| 2 | +import { relative, sep } from 'upath' |
2 | 3 |
|
3 | 4 | import { name, version } from '../package.json'
|
4 | 5 |
|
@@ -40,9 +41,28 @@ const compositionApiModule: Module<never> = function compositionApiModule() {
|
40 | 41 | })
|
41 | 42 | })
|
42 | 43 |
|
43 |
| - // Register the Vue Composition API before any other layouts |
44 |
| - |
45 |
| - this.addLayout(resolveRelativePath('runtime/templates/layout.js'), '0') |
| 44 | + // Register the Vue Composition API |
| 45 | + |
| 46 | + if (nuxtOptions.features.middleware) { |
| 47 | + const middleware = addResolvedTemplate.call(this, 'register.js') |
| 48 | + this.nuxt.hook( |
| 49 | + 'build:templates', |
| 50 | + ({ templateVars }: { templateVars: Record<string, any> }) => { |
| 51 | + templateVars.middleware.unshift({ |
| 52 | + src: middleware, |
| 53 | + dst: '.' + sep + relative(nuxtOptions.buildDir, middleware), |
| 54 | + name: 'compositionApiRegistration', |
| 55 | + }) |
| 56 | + } |
| 57 | + ) |
| 58 | + } else if (nuxtOptions.features.layouts) { |
| 59 | + this.addLayout(resolveRelativePath('runtime/templates/layout.js'), '0') |
| 60 | + } else { |
| 61 | + const dst = addResolvedTemplate.call(this, 'register.js') |
| 62 | + this.nuxt.hook('modules:done', () => |
| 63 | + this.nuxt.hook('build:before', () => nuxtOptions.plugins.unshift(dst)) |
| 64 | + ) |
| 65 | + } |
46 | 66 |
|
47 | 67 | // If we're using nuxt-vite, register vite plugin & inject configuration
|
48 | 68 |
|
|
0 commit comments