Skip to content

Commit f58179e

Browse files
committed
feat(config): add option to enable disable the module.
1 parent 9bb7b3a commit f58179e

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

playground/nuxt.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export default defineNuxtConfig({
55
},
66
},
77
modules: ["../src/module"],
8-
utm: {},
8+
utm: {
9+
enabled: true,
10+
},
911
devtools: { enabled: true },
1012
});

src/module.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import { defineNuxtModule, addPlugin, createResolver } from "@nuxt/kit";
22

3-
// Module options TypeScript interface definition
4-
export interface ModuleOptions {}
3+
export interface ModuleOptions {
4+
enabled: boolean;
5+
}
56

67
export default defineNuxtModule<ModuleOptions>({
78
meta: {
89
name: "utm",
910
configKey: "utm",
1011
},
11-
// Default configuration options of the Nuxt module
12-
defaults: {},
13-
setup() {
12+
defaults: {
13+
enabled: true,
14+
},
15+
setup(options, nuxt) {
1416
const resolver = createResolver(import.meta.url);
1517

16-
// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
17-
addPlugin(resolver.resolve("./runtime/plugin"));
18+
if (options.enabled) {
19+
// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
20+
addPlugin(resolver.resolve("./runtime/plugin"));
21+
}
1822
},
1923
});

0 commit comments

Comments
 (0)