Skip to content

Commit

Permalink
feat(config): add option to enable disable the module.
Browse files Browse the repository at this point in the history
  • Loading branch information
sadjow committed Nov 21, 2024
1 parent f1ca098 commit 2e46656
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
4 changes: 3 additions & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export default defineNuxtConfig({
},
},
modules: ["../src/module"],
utm: {},
utm: {
enabled: true,
},
devtools: { enabled: true },
});
33 changes: 21 additions & 12 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import { defineNuxtModule, addPlugin, addImports, createResolver } from "@nuxt/kit";
import {
defineNuxtModule,
addPlugin,
addImports,
createResolver,
} from "@nuxt/kit";

// Module options TypeScript interface definition
export interface ModuleOptions {}
export interface ModuleOptions {
enabled: boolean;
}

export default defineNuxtModule<ModuleOptions>({
meta: {
name: "utm",
configKey: "utm",
},
// Default configuration options of the Nuxt module
defaults: {},
setup() {
defaults: {
enabled: true,
},
setup(options, nuxt) {

Check warning on line 20 in src/module.ts

View workflow job for this annotation

GitHub Actions / build (18)

'nuxt' is defined but never used

Check warning on line 20 in src/module.ts

View workflow job for this annotation

GitHub Actions / build (20)

'nuxt' is defined but never used
const resolver = createResolver(import.meta.url);

// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
addPlugin(resolver.resolve("./runtime/plugin"));
addImports({
name: 'useNuxtUTM',
from: resolver.resolve('runtime/composables'),
})
if (options.enabled) {
// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
addPlugin(resolver.resolve("./runtime/plugin"));
addImports({
name: "useNuxtUTM",
from: resolver.resolve("runtime/composables"),
});
}
},
});

0 comments on commit 2e46656

Please sign in to comment.