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

Commit

Permalink
refactor: extract vca registration into an external/shared js file (#470
Browse files Browse the repository at this point in the history
)
  • Loading branch information
danielroe authored Apr 28, 2021
1 parent 13493b2 commit 16e21eb
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 37 deletions.
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ module.exports = {
setupFiles: ['<rootDir>/test/unit/setup'],
moduleNameMapper: {
'@nuxtjs/composition-api/dist/globals': '<rootDir>/src/globals',
'@nuxtjs/composition-api/dist/runtime/register':
'<rootDir>/src/runtime/register',
},
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"./package.json": "./package.json",
"./dist/babel-plugin": "./dist/babel-plugin.js",
"./dist/globals": "./dist/globals.js",
"./dist/runtime/templates/*": "./dist/runtime/templates/*"
"./dist/runtime/templates/*": "./dist/runtime/templates/*",
"./dist/runtime/register": "./dist/runtime/register.js"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
5 changes: 4 additions & 1 deletion siroc.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { defineSirocConfig } from 'siroc'

export default defineSirocConfig({
rollup: {
externals: ['@nuxtjs/composition-api/dist/globals'],
externals: [
'@nuxtjs/composition-api/dist/globals',
'@nuxtjs/composition-api/dist/runtime/register',
],
},
})
23 changes: 0 additions & 23 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,6 @@ const compositionApiModule: Module<never> = function compositionApiModule() {
})
})

// Register the Vue Composition API

if (nuxtOptions.features.middleware) {
const middleware = addResolvedTemplate.call(this, 'register.js')
this.nuxt.hook(
'build:templates',
({ templateVars }: { templateVars: Record<string, any> }) => {
templateVars.middleware.unshift({
src: middleware,
dst: '.' + sep + relative(nuxtOptions.buildDir, middleware),
name: 'compositionApiRegistration',
})
}
)
} else if (nuxtOptions.features.layouts) {
this.addLayout(resolveRelativePath('runtime/templates/layout.js'), '0')
} else {
const dst = addResolvedTemplate.call(this, 'register.js')
this.nuxt.hook('modules:done', () =>
this.nuxt.hook('build:before', () => nuxtOptions.plugins.unshift(dst))
)
}

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

this.nuxt.hook('vite:extend', async (ctx: any) => {
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import '@nuxtjs/composition-api/dist/runtime/register'

export { useAsync } from './async'
export { defineComponent } from './component'
export { useContext, withContext } from './context'
Expand Down
2 changes: 0 additions & 2 deletions src/runtime/templates/register.js → src/runtime/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ import Vue from 'vue'
import CompositionApi from '@vue/composition-api'

Vue.use(CompositionApi)

export default {}
10 changes: 0 additions & 10 deletions src/runtime/templates/layout.js

This file was deleted.

5 changes: 5 additions & 0 deletions test/fixture/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ console.log('Testing', inDevelopment ? 'source' : 'built', 'module')

export default <NuxtConfig>{
alias: {
'@nuxtjs/composition-api/dist/runtime/register': join(
rootDir,
inDevelopment ? 'src' : 'dist',
'runtime/register'
),
'@nuxtjs/composition-api/dist/globals': join(
rootDir,
inDevelopment ? 'src' : 'dist',
Expand Down

0 comments on commit 16e21eb

Please sign in to comment.