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

Commit

Permalink
feat: expose modules (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu authored Jan 13, 2023
1 parent b1763e7 commit 19d103d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
externals: ['#app/entry', '#build/root-component.mjs', 'vite'],
externals: ['#app/entry', '#build/root-component.mjs', '@nuxt/schema', 'vite'],
failOnWarn: false,
})
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
"import": "./dist/utils.mjs",
"types": "./dist/utils.d.ts"
},
"./module": {
"require": "./dist/module.cjs",
"import": "./dist/module.mjs",
"types": "./dist/module.d.ts"
},
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { loadNuxt, buildNuxt } from '@nuxt/kit'
import type { Nuxt } from '@nuxt/schema'
import type { InlineConfig as VitestConfig } from 'vitest'
import { InlineConfig, mergeConfig, defineConfig } from 'vite'
import autoImportMock from './modules/auto-import-mock'
import modules from './module'

// https://github.com/nuxt/framework/issues/6496
async function getNuxtAndViteConfig(rootDir = process.cwd()) {
Expand All @@ -17,7 +17,7 @@ async function getNuxtAndViteConfig(rootDir = process.cwd()) {
},
},
})
nuxt.options.modules.push(autoImportMock)
nuxt.options.modules.push(modules)
await nuxt.ready()

return new Promise<{ nuxt: Nuxt, config: InlineConfig }>((resolve, reject) => {
Expand Down
11 changes: 11 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineNuxtModule, installModule } from '@nuxt/kit'
import autoImportMock from './modules/auto-import-mock'

export default defineNuxtModule({
meta: {
name: 'vitest-env',
},
async setup() {
await installModule(autoImportMock)
},
})
2 changes: 1 addition & 1 deletion src/modules/auto-import-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface MockInfo {
*/
export default defineNuxtModule({
meta: {
name: 'vitest:auto-import-mock',
name: 'vitest-env:auto-import-mock',
},
setup(_, nuxt) {
let imports: Import[] = []
Expand Down

0 comments on commit 19d103d

Please sign in to comment.