Skip to content

Commit

Permalink
fix: mark runtime/ directory as external
Browse files Browse the repository at this point in the history
resolves #242
  • Loading branch information
danielroe committed Apr 25, 2024
1 parent 3a54a33 commit 7a68e1e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions example/src/module.ts
@@ -1,8 +1,12 @@
import { defineNuxtModule, addPlugin, createResolver } from '@nuxt/kit'

// https://github.com/nuxt/module-builder/issues/242
import type { SharedTypeFromRuntime } from './runtime/plugins/plugin'

// Module options TypeScript interface definition
export interface ModuleOptions {
apiKey: string
shared?: SharedTypeFromRuntime
}

export interface ModuleHooks {
Expand Down Expand Up @@ -33,6 +37,9 @@ export default defineNuxtModule<ModuleOptions>({
setup(_options, _nuxt) {
const resolver = createResolver(import.meta.url)

// @ts-expect-error type should be resolved
_options.shared = 'not-shared-type'

// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
addPlugin(resolver.resolve('./runtime/plugins/plugin'))
},
Expand Down
2 changes: 2 additions & 0 deletions example/src/runtime/plugins/plugin.ts
@@ -1,5 +1,7 @@
import { defineNuxtPlugin } from '#app'

export type SharedTypeFromRuntime = 'shared-type'

export default defineNuxtPlugin(() => {
console.log('Plugin injected by my-module!')
return {
Expand Down
1 change: 1 addition & 0 deletions src/commands/build.ts
Expand Up @@ -58,6 +58,7 @@ export default defineCommand({
cjsBridge: true,
},
externals: [
/src\/runtime/,
'@nuxt/schema',
'@nuxt/schema-nightly',
'@nuxt/schema-edge',
Expand Down

0 comments on commit 7a68e1e

Please sign in to comment.