@shopware/nuxt-module
Version:
Nuxt 3 module for Shopware Frontends
58 lines (54 loc) • 1.85 kB
JavaScript
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);
const shopwareConfig = nuxt.options.runtimeConfig?.public?.shopware ?? void 0;
nuxt.options.runtimeConfig.public.shopware = defu(
nuxt.options.runtimeConfig.public.shopware || {},
options || {}
);
if (isConfigDeprecated(shopwareConfig)) {
logger.warn(
"You are using deprecated configuration (shopwareEndpoint or shopwareAccessToken). 'shopware' prefix is not needed anymore. Please update your _nuxt.config.ts_ "
);
}
if (shopwareConfig?.endpoint) {
logger.info(
`You are using SSR Shopware API endpoint: ${shopwareConfig.endpoint}`
);
}
logger.info(
`CSR Shopware API endpoint: ${shopwareConfig?.endpoint ?? shopwareConfig?.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 };