diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index 05f5cf2..f4a5b0b 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -1,7 +1,8 @@ export default defineNuxtConfig({ modules: ['../src/module', '@pinia/nuxt'], nuxt3UIKit: { - theme: 'green' + theme: 'dark', + components: ['pagesTestVuetify', 'partsFooterDefault', 'partsCard', 'partsForms', 'partsErgVacancies', 'partsHeaderDefault', 'partsHeaderErg'] }, devtools: { enabled: true }, build: { diff --git a/src/module.ts b/src/module.ts index d4699da..d664c2a 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1,87 +1,128 @@ -import {addComponent, addPlugin, createResolver, defineNuxtModule} from '@nuxt/kit' +import { + addComponent, + addPlugin, + createResolver, + defineNuxtModule, +} from "@nuxt/kit"; // Module options TypeScript interface definition -export interface ModuleOptions {} +export interface ModuleOptions { + theme: string; + components: string[]; +} export default defineNuxtModule({ meta: { - name: 'nuxt3-ui-kit', - configKey: 'nuxt3UIKit' + name: "nuxt3-ui-kit", + configKey: "nuxt3UIKit", }, // Default configuration options of the Nuxt module defaults: { - theme: 'light' + theme: "light", + components: [] }, - setup (options, nuxt) { - const resolver = createResolver(import.meta.url) - const runtimeDir = resolver.resolve('./runtime') + setup(options, nuxt) { + const resolver = createResolver(import.meta.url); + const runtimeDir = resolver.resolve("./runtime"); - const isDevelopment = runtimeDir.endsWith('src/runtime') || runtimeDir.endsWith('src\\runtime') + const isDevelopment = + runtimeDir.endsWith("src/runtime") || runtimeDir.endsWith("src\\runtime"); - const extension = isDevelopment ? 'scss' : 'css' + const extension = isDevelopment ? "scss" : "css"; // Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack` - addPlugin(resolver.resolve('./runtime/plugin')) + addPlugin(resolver.resolve("./runtime/plugin")); - nuxt.options.css.push(resolver.resolve(`./runtime/plugins/vuetify/styles.${extension}`)) + nuxt.options.css.push( + resolver.resolve(`./runtime/plugins/vuetify/styles.${extension}`) + ); // Components - addComponent({ - name: 'pagesTestVuetify', // name of the component to be used in vue templates - filePath: resolver.resolve('runtime/components/Pages/TestVuetify.vue') - }) - - addComponent({ - name: 'partsFooterDefault', // name of the component to be used in vue templates - filePath: resolver.resolve('runtime/components/Parts/Footer/Default.vue') - }) - - addComponent({ - name: 'partsCard', // name of the component to be used in vue templates - filePath: resolver.resolve('runtime/components/Parts/Card.vue') - }) - - addComponent({ - name: 'partsForms', // name of the component to be used in vue templates - filePath: resolver.resolve('runtime/components/Parts/Forms.vue') - }) - - addComponent({ - name: 'partsErgVacancies', // name of the component to be used in vue templates - filePath: resolver.resolve('runtime/components/Parts/ErgVacancies.vue') - }) - // Header - addComponent( { - name: 'partsHeaderDefault', - filePath: resolver.resolve('runtime/components/Parts/Header/Default.vue') - }) + if (options.components.includes("pagesTestVuetify")) { + addComponent({ + name: "pagesTestVuetify", // name of the component to be used in vue templates + filePath: resolver.resolve("runtime/components/Pages/TestVuetify.vue"), + }); + } + + if (options.components.includes("partsFooterDefault")) { + addComponent({ + name: "partsFooterDefault", // name of the component to be used in vue templates + filePath: resolver.resolve( + "runtime/components/Parts/Footer/Default.vue" + ), + }); + } + + if (options.components.includes("partsCard")) { + addComponent({ + name: "partsCard", // name of the component to be used in vue templates + filePath: resolver.resolve("runtime/components/Parts/Card.vue"), + }); + } + + if (options.components.includes("partsForms")) { + addComponent({ + name: "partsForms", // name of the component to be used in vue templates + filePath: resolver.resolve("runtime/components/Parts/Forms.vue"), + }); + } + + if (options.components.includes("partsErgVacancies")) { + addComponent({ + name: "partsErgVacancies", // name of the component to be used in vue templates + filePath: resolver.resolve("runtime/components/Parts/ErgVacancies.vue"), + }); + } - addComponent( { - name: 'partsHeaderErg', - filePath: resolver.resolve('runtime/components/Parts/Header/Erg.vue') - }) + // Header + if (options.components.includes("partsHeaderDefault")) { + addComponent({ + name: "partsHeaderDefault", + filePath: resolver.resolve( + "runtime/components/Parts/Header/Default.vue" + ), + }); + } + + if (options.components.includes("partsHeaderErg")) { + addComponent({ + name: "partsHeaderErg", + filePath: resolver.resolve("runtime/components/Parts/Header/Erg.vue"), + }); + } // Modal - addComponent( { - name: 'partsModal', - filePath: resolver.resolve('runtime/components/Parts/Modal.vue') - }) + if (options.components.includes("partsModal")) { + addComponent({ + name: "partsModal", + filePath: resolver.resolve("runtime/components/Parts/Modal.vue"), + }); + } //Slider - addComponent({ - name: 'partsSlider', - filePath: resolver.resolve('runtime/components/Parts/Slider.vue') - }) - - addComponent({ - name: 'partsNews', - filePath: resolver.resolve('runtime/components/Parts/News.vue') - }) - - addComponent({ - name: 'partsFilesDownloadFiles', - filePath: resolver.resolve('runtime/components/Parts/Files/DownloadFiles.vue') - }) - } -}) + if (options.components.includes("partsSlider")) { + addComponent({ + name: "partsSlider", + filePath: resolver.resolve("runtime/components/Parts/Slider.vue"), + }); + } + + if (options.components.includes("partsNews")) { + addComponent({ + name: "partsNews", + filePath: resolver.resolve("runtime/components/Parts/News.vue"), + }); + } + + if (options.components.includes("partsFilesDownloadFiles")) { + addComponent({ + name: "partsFilesDownloadFiles", + filePath: resolver.resolve( + "runtime/components/Parts/Files/DownloadFiles.vue" + ), + }); + } + }, +});