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 May 18, 2024
1 parent 9bb7b3a commit f58179e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 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 },
});
18 changes: 11 additions & 7 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { defineNuxtModule, addPlugin, 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 15 in src/module.ts

View workflow job for this annotation

GitHub Actions / build (18)

'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"));
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"));
}
},
});

0 comments on commit f58179e

Please sign in to comment.