shopware/frontends - nuxt3-module
Nuxt module that allows you to set up a Nuxt 3 project with Shopware Frontends. It provides the composables and api-client packages.
If you want to use these packages with a different Vue.js framework, see the guide for using Shopware Frontends in a custom project.
Features
Setup
Install npm package:
pnpm add -D @shopware-pwa/nuxt3-module
yarn add --dev @shopware-pwa/nuxt3-module
npm i @shopware-pwa/nuxt3-module --save-dev
Then, register the module by editing nuxt.config.js
or (.ts
) file (by extending modules
array):
export default defineNuxtConfig({
modules: [, "@shopware-pwa/nuxt3-module"],
shopware: {
endpoint: "https://demo-frontends.shopware.store",
accessToken: "SWSCBHFSNTVMAWNZDNFKSHLAYW",
},
runtimeConfig: {
public: {
shopware: {
endpoint: "https://demo-frontends.shopware.store",
accessToken: "SWSCBHFSNTVMAWNZDNFKSHLAYW",
},
},
},
});
Set up your own API instance under shopware
key or by extending public runtimeConfiguration
in the same file. The nuxt module (and vue plugin) will use those values (runtimeConfig will always override the base ones).
Basic usage
Now you can use any composable function you need without extra import:
<script setup>
const { login } = useUser();
const { refreshSessionContext } = useSessionContext();
refreshSessionContext();
</script>
The information about the session is kept in a cookie (sw-context-token
) and used in every request made by any composable or directly, invoked by api instance
:
<script>
const { apiClient } = useShopwareContext();
const apiResponse = await apiClient.invoke();
</script>
TypeScript support
All composable functions are fully typed with TypeScript and they are registed globally in Nuxt.js application, so the type hinting will help you to work with all of them.
📦 Advanced packaging
Internally, the module uses API Client and Composables packages, configured together to make everything working well. If you need to check how it's working on a different version of one of them, install a package locally in your project (to be installed and available in project's package.json
file), then the Nuxt module will use yours. Keep in mind that the different configuration may lead to unexpected behavior.
Links
Changelog
Full changelog for stable version is available here
Latest changes: 0.0.0-canary-20240917072134
Patch Changes
-
#1207 7531874
Thanks @mkucmus! - Improvements within a nuxt module and the plugin:
- properly loading a
sw-context-token
cookie in SSR - exposing an API client instance provided in a nuxt plugin
- adds corresponding types
const { $shopwareApiClient } = useNuxtApp();
await $shopwareApiClient.invoke("readContext get /context");
-
Updated dependencies [6ee2f90
, 6ee2f90
]:
- @shopware-pwa/composables-next@0.0.0-canary-20240917072134
- @shopware-pwa/helpers-next@0.0.0-canary-20240917072134