UNPKG

@shopware/nuxt-module

Version:
57 lines (53 loc) 1.9 kB
import { addCustomTab } from '@nuxt/devtools-kit'; import { defineNuxtModule, useLogger, createResolver, addPlugin } from '@nuxt/kit'; import { defu } from 'defu'; import 'node:fs'; import { dirname, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; const distDir = dirname(fileURLToPath(import.meta.url)); const pkgDir = resolve(distDir, ".."); resolve(pkgDir, "./node_modules"); function isConfigDeprecated(config) { return Boolean(config?.shopwareEndpoint || config?.shopwareAccessToken); } const MODULE_ID = "@shopware/nuxt3"; const index = defineNuxtModule({ meta: { name: MODULE_ID, configKey: "shopware" }, async setup(options, nuxt) { const logger = useLogger(MODULE_ID); const resolver = createResolver(import.meta.url); nuxt.options.runtimeConfig.public.shopware = defu( nuxt.options.runtimeConfig.public.shopware || {}, options || {} ); if (isConfigDeprecated(nuxt.options?.runtimeConfig?.public?.shopware)) { logger.warn( "You are using deprecated configuration (shopwareEndpoint or shopwareAccessToken). 'shopware' prefix is not needed anymore. Please update your _nuxt.config.ts_ " ); } if (nuxt.options?.runtimeConfig?.shopware?.endpoint) { logger.info( `You are using SSR Shopware API endpoint: ${nuxt.options.runtimeConfig.shopware.endpoint}` ); } logger.info( `CSR Shopware API endpoint: ${nuxt.options.runtimeConfig.public?.shopware?.endpoint ?? nuxt.options.runtimeConfig.public?.shopware?.shopwareEndpoint}` ); addPlugin({ src: resolver.resolve("../plugin.ts") }); addCustomTab({ name: "shopware-frontends", title: "Shopware Frontends", icon: "fa6-brands:shopware", view: { type: "iframe", src: "https://frontends.shopware.com/" } }); } }); export { index as default };