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

Commit 16e21eb

Browse files
authored
refactor: extract vca registration into an external/shared js file (#470)
1 parent 13493b2 commit 16e21eb

File tree

8 files changed

+15
-37
lines changed

8 files changed

+15
-37
lines changed

jest.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ module.exports = {
88
setupFiles: ['<rootDir>/test/unit/setup'],
99
moduleNameMapper: {
1010
'@nuxtjs/composition-api/dist/globals': '<rootDir>/src/globals',
11+
'@nuxtjs/composition-api/dist/runtime/register':
12+
'<rootDir>/src/runtime/register',
1113
},
1214
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"./package.json": "./package.json",
2727
"./dist/babel-plugin": "./dist/babel-plugin.js",
2828
"./dist/globals": "./dist/globals.js",
29-
"./dist/runtime/templates/*": "./dist/runtime/templates/*"
29+
"./dist/runtime/templates/*": "./dist/runtime/templates/*",
30+
"./dist/runtime/register": "./dist/runtime/register.js"
3031
},
3132
"main": "./dist/index.js",
3233
"module": "./dist/index.mjs",

siroc.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { defineSirocConfig } from 'siroc'
22

33
export default defineSirocConfig({
44
rollup: {
5-
externals: ['@nuxtjs/composition-api/dist/globals'],
5+
externals: [
6+
'@nuxtjs/composition-api/dist/globals',
7+
'@nuxtjs/composition-api/dist/runtime/register',
8+
],
69
},
710
})

src/module.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,6 @@ const compositionApiModule: Module<never> = function compositionApiModule() {
4949
})
5050
})
5151

52-
// Register the Vue Composition API
53-
54-
if (nuxtOptions.features.middleware) {
55-
const middleware = addResolvedTemplate.call(this, 'register.js')
56-
this.nuxt.hook(
57-
'build:templates',
58-
({ templateVars }: { templateVars: Record<string, any> }) => {
59-
templateVars.middleware.unshift({
60-
src: middleware,
61-
dst: '.' + sep + relative(nuxtOptions.buildDir, middleware),
62-
name: 'compositionApiRegistration',
63-
})
64-
}
65-
)
66-
} else if (nuxtOptions.features.layouts) {
67-
this.addLayout(resolveRelativePath('runtime/templates/layout.js'), '0')
68-
} else {
69-
const dst = addResolvedTemplate.call(this, 'register.js')
70-
this.nuxt.hook('modules:done', () =>
71-
this.nuxt.hook('build:before', () => nuxtOptions.plugins.unshift(dst))
72-
)
73-
}
74-
7552
// If we're using nuxt-vite, register vite plugin & inject configuration
7653

7754
this.nuxt.hook('vite:extend', async (ctx: any) => {

src/runtime/composables/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import '@nuxtjs/composition-api/dist/runtime/register'
2+
13
export { useAsync } from './async'
24
export { defineComponent } from './component'
35
export { useContext, withContext } from './context'

src/runtime/templates/register.js renamed to src/runtime/register.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@ import Vue from 'vue'
22
import CompositionApi from '@vue/composition-api'
33

44
Vue.use(CompositionApi)
5-
6-
export default {}

src/runtime/templates/layout.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/fixture/nuxt.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ console.log('Testing', inDevelopment ? 'source' : 'built', 'module')
1515

1616
export default <NuxtConfig>{
1717
alias: {
18+
'@nuxtjs/composition-api/dist/runtime/register': join(
19+
rootDir,
20+
inDevelopment ? 'src' : 'dist',
21+
'runtime/register'
22+
),
1823
'@nuxtjs/composition-api/dist/globals': join(
1924
rootDir,
2025
inDevelopment ? 'src' : 'dist',

0 commit comments

Comments
 (0)