Skip to content

Commit 05b86c6

Browse files
authored
docs: update the Theme document (vuestorefront#6608)
1 parent 4a2da20 commit 05b86c6

File tree

6 files changed

+99
-91
lines changed

6 files changed

+99
-91
lines changed

packages/core/docs/.vuepress/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ module.exports = {
165165
children: [
166166
['/integrate/extending-vue-storefront', 'Extending Vue Storefront'],
167167
['/integrate/extending-integrations', 'Extending integrations'],
168-
['/integrate/integration-guide', 'Integrating eCommerce platform'],
168+
['/integrate/integration-guide', 'Integrating e-commerce platform'],
169169
['/integrate/cms', 'Integrating CMS platform'],
170170
['/integrate/cache-driver', 'Integrating cache driver']
171171
]

packages/core/docs/getting-started/layouts-and-routing.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,41 @@ export default {
113113
};
114114
```
115115

116+
## Changing base path
117+
118+
There are cases when your store is served under a specific path, eg. `example.com/shop/`. To make Vue.js router aware of this, you need to update the configuration in the `nuxt.config.js`:
119+
120+
```javascript
121+
// nuxt.config.js
122+
123+
export default {
124+
router: {
125+
base: "/shop/"
126+
}
127+
};
128+
```
129+
130+
Unfortunately not all links in your application will detect this. You can fix it, by wrap all relative links and paths to assets in `addBasePath` helper.
131+
132+
```vue
133+
<template>
134+
<SfImage :src="addBasePath('/imageA.webp')" />
135+
<SfBanner :image="addBasePath('/bannerB.png')" />
136+
</template>
137+
138+
<script>
139+
import { addBasePath } from '@vue-storefront/core';
140+
141+
export default {
142+
setup() {
143+
return {
144+
addBasePath
145+
};
146+
}
147+
};
148+
</script>
149+
```
150+
116151
## Navigating between pages
117152

118153
To navigate between pages within your application, use the [NuxtLink](https://nuxtjs.org/docs/features/nuxt-components/#the-nuxtlink-component) component, instead of the traditional `<a>` tag. While you can use the `<a>` tag for external links, using the `<NuxtLink />` for internal links will ensure that you make use of the Single-Page Navigation capabilities that Nuxt.js provides.
Lines changed: 54 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,105 @@
11
# Theme
22

3-
## Storefront UI
3+
A project without any theme would just show a blank page, but if you have seen any of Vue Storefront demos or created a project using our CLI, you know that's not the case. So what makes it look like it does?
44

5-
<center>
6-
<img src="../images/theme/storefront-ui.jpg" />
7-
</center>
5+
This page will describe what makes the default theme, how to customize it, and what tricks we use to improve the performance.
86

9-
Almost every component in our default theme uses components whose names start with `Sf`. These come from [Storefront UI](http://storefrontui.io/) - a design system and library of Vue.js components dedicated to e-commerce, maintained by the Vue Storefront core team. It comes with [Storybook](https://storybook.storefrontui.io/) to help you customize and test the components.
7+
## What's makes a default theme
108

11-
The library is fully customizable. It can be used in different contexts and with different designs.
12-
It's excellent for the multi-tenancy model as a shared UI library that can be customized differently for each tenant.
9+
Although, at first glance, it might look like all of our e-commerce integrations use the same exact theme, it's not the case. All of them are built upon the same base theme and modify it to work well and cover features of a given platform. This means that some integrations might have more pages, different UI elements, or additional Nuxt.js modules or plugins.
1310

14-
To learn more about Storefront UI, please check its [Documentation](https://docs.storefrontui.io/).
11+
For this reason, in this section, we will focus only on the common parts of all themes.
1512

16-
::: tip Want to use another UI library? No problem!
17-
If you don't want to use Storefront UI, feel free to remove it from your project. It's just a UI layer, and the project can work with any other UI library or a custom code.
18-
:::
13+
### Preinstalled modules and libraries
1914

20-
## Customizing the theme
15+
Every new Vue Storefront project comes with a set of preinstalled Nuxt.js modules and plugins, as well as Vue.js libraries. These packages offer a variety of features from cookie handling to form validation and are used by the base theme. You can remove some of them, but only if you decide to create a custom theme from scratch.
2116

22-
### Changing existing pages, components, and layouts
17+
#### Nuxt.js modules and plugins
2318

24-
To update the existing components, you need to identify them first. Vue.js Devtools helps us in that. Open the tool and click on the `Select` button above the component tree, then click on the DOM element you want to update. One of the components in the tree should get highlighted. You can look for the component with the same name in the `layout`, `pages`, or `components` directories and update it to your needs. However, there are few exceptions to this rule.
19+
- [`@nuxt/typescript-build`](https://typescript.nuxtjs.org/) - for TypeScript support,
20+
- [`@nuxtjs/pwa`](https://pwa.nuxtjs.org/) - for PWA functionalities,
21+
- [`@nuxtjs/composition-api`](https://composition-api.nuxtjs.org/) - for Composition API support,
22+
- [`@nuxtjs/style-resources`](https://www.npmjs.com/package/@nuxtjs/style-resources) - for importing SASS variables globally,
23+
- [`nuxt-i18n`](https://i18n-legacy.nuxtjs.org/) - for internationalization (translations and price formatting),
24+
- [`nuxt-purgecss`](https://purgecss.com/guides/nuxt.html) - for removing unused CSS from the final build,
25+
- [`cookie-universal-nuxt`](https://www.npmjs.com/package/cookie-universal-nuxt) - for handling cookies on the server (SSR) and client (browser).
2526

26-
#### `Sf` components
27+
#### Vue.js libraries
2728

28-
If the name of the component starts with `Sf` (indicating that it comes from Storefront UI), you should refer to the direct **parent** component. The behavior and look of such components can be changed by passing different properties and using slots. Refer to the StorefrontUI documentation linked above for more information.
29+
- [`vee-validate`](https://vee-validate.logaretm.com/v3) - for frontend form validation,
30+
- [`vue-scrollto/nuxt`](https://www.npmjs.com/package/vue-scrollto) - for smooth scrolling to HTML elements,
31+
- [`vue-lazy-hydration`](https://www.npmjs.com/package/vue-lazy-hydration) - for delaying hydration and improving performance.
2932

30-
#### `LazyHydrate` and `Anonymous Component` components
33+
### Storefront UI
3134

32-
These two components come from the `vue-lazy-hydration` library and are wrappers around other components. In Vue Storefront, they are used to improve the performance by deferring the hydration process (when components become interactive) and don't affect the look of other components.
35+
<figure style="text-align: center">
36+
<img
37+
src="../images/storefront-ui.webp"
38+
alt="StorefrontUI logo and default theme"
39+
/>
40+
<figcaption style="font-size: 0.9rem">(Click to zoom)</figcaption>
41+
</figure>
3342

34-
If you encounter one of these components, you should refer to the direct **child** component.
43+
Almost every page in our default theme uses components whose names start with `Sf`. These come from the [Storefront UI](http://storefrontui.io/) — a design system and library of Vue.js components dedicated to e-commerce, maintained by the Vue Storefront team. Every component can be heavily customized using [props](https://vuejs.org/v2/guide/components-props.html) and [slots](https://vuejs.org/v2/guide/components-slots.html).
3544

36-
### Router base property
45+
Please check [Storefront UI documentation](https://docs.storefrontui.io/) to learn more and interactively customize and test the components.
3746

38-
There is an option to set base URL for your store.
47+
::: tip Want to use another UI library? No problem!
48+
If you don't want to use Storefront UI, feel free to remove it from your project. It's just a UI layer, and the project can work with any other UI library or a custom code.
49+
:::
3950

40-
This can be useful if you need to serve your store as a different context root, from within a bigger Web site.
51+
## How to customize the theme
4152

42-
Add following configuration to `nuxt.config.js`
43-
```javascript
44-
// nuxt.config.js
53+
Every default theme will need customization at some point. Regardless of how complex the changes are, we recommend reusing as much from the default theme as possible. This will not only save you time but will likely reduce the number of bugs, thanks to the time we spend on stabilization and testing.
4554

46-
export default {
47-
router: {
48-
base: "/myShop/"
49-
}
50-
};
51-
```
55+
### Updating layouts, pages, and components
5256

53-
:::warning Be careful
54-
When using base router property you need to wrap all assets relative links in addBasePath(), this will automatically add base path to them and prevent redirects. (example below)
55-
:::
57+
To update the existing component, you need to identify it first, and Vue.js Devtools is invaluable in this. Open the Vue.js Devtools, right-click the DOM element you want to update, and select `Inspect Vue component`. One of the components in the tree in Vue.js Devtools should get highlighted. You can look for the component with the same name in the `layout`, `pages`, or `components` directories and update it to your needs. However, there are a few exceptions to this rule described below.
5658

59+
#### `Sf` components
5760

61+
If the component's name starts with `Sf`, it means that it comes from [StorefrontUI](https://storefrontui.io/) library. The look and behavior of such components are controlled using props and slots passed from the direct **parent** component.
5862

59-
```javascript
60-
//use addBasePath on relative url
61-
<SfImage :src="addBasePath(`/homepage/imageA.webp`)" />
62-
<SfBanner :image="addBasePath('/homepage/bannerA.png')" />
63-
64-
//In theme file import addBasePath from vue-storefront core
65-
import { addBasePath } from '@vue-storefront/core';
66-
67-
setup() {
68-
return {
69-
// if you want to use it in template you need to exprt it
70-
addBasePath
71-
}
72-
}
73-
```
63+
#### `LazyHydrate` and `Anonymous Component` components
7464

75-
## Updating styles
65+
These two components come from the [vue-lazy-hydration](https://github.com/maoberlehner/vue-lazy-hydration) library and are wrappers around other components. They are used to improve the performance by deferring the hydration process (making components interactive) and don't affect the look of other components. The behavior of such components is controlled using props passed from the direct **parent** component.
7666

77-
There are few ways of updating the default styles. Below we describe the most optimal ways for the most common cases.
67+
### Updating styles
7868

79-
### Adding global styleheet
69+
There are a few ways of updating the default styles. Below we describe the most optimal methods for the most common cases.
70+
71+
#### Adding global styleheet
8072

8173
To add global styles applied to all pages, use the [css property](https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-css/) in `nuxt.config.js`.
8274

83-
### Adding stylesheet to specific layout, page, or component
75+
#### Adding stylesheet to specific layout, page, or component
8476

85-
To add a stylesheet to a specific component, use `@import` regardless if you are using CSS, SCSS, or LESS.
77+
To add a stylesheet to a specific component, use `@import` regardless of whether you are using CSS, SCSS, or LESS.
8678

8779
```vue
8880
<style>
8981
@import "@/assets/stylesheet.css";
9082
</style>
9183
```
9284

93-
### Using variables, mixins, and function in components
85+
#### Using variables, mixins, and function in components
9486

95-
Usually, to access style variables, mixins, and functions, we have to import them in every component separately. Thanks to [@nuxtjs/style-resources](https://github.com/nuxt-community/style-resources-module#readme) module, we can register them in `nuxt.config.js` and access them without extra `@import` statements.
87+
Usually, to access style variables, mixins, and functions, we import them in every component separately. Thanks to the [@nuxtjs/style-resources](https://github.com/nuxt-community/style-resources-module#readme) module, we can register them in `nuxt.config.js` and access them without extra `@import` statements.
9688

9789
:::danger Be careful
98-
Stylesheets in `styleResources` should **only** contain variables, mixins, and functions. During the build process, the components import these stylesheets. Any styles declared in them are added to every component, which can significantly hurt the performance and application size.
90+
Stylesheets in `styleResources` should **only** contain variables, mixins, and functions. During the build process, the components import these stylesheets. Any **styles** declared in them are added to every component, significantly impacting the performance and application size.
9991
:::
10092

10193
We use this approach to have access to StorefrontUI helpers in all components:
10294

103-
```js
95+
```javascript
10496
// nuxt.config.js
97+
10598
export default {
10699
styleResources: {
107-
scss: [require.resolve('@storefront-ui/shared/styles/_helpers.scss', { paths: [process.cwd()] })]
100+
scss: [
101+
require.resolve('@storefront-ui/shared/styles/_helpers.scss', { paths: [process.cwd()] })
102+
]
108103
},
109104
};
110105
```
111-
112-
## Preinstalled modules and libraries
113-
114-
Below you can find a list of the most important Nuxt Modules and libraries that come preinstalled with the default theme:
115-
116-
### Nuxt.js modules
117-
118-
- `@nuxtjs/pwa`;
119-
- `nuxt-i18n`;
120-
- `@vue-storefront/nuxt`;
121-
- `@nuxtjs/composition-api`;
122-
- `@nuxt/typescript-build`;
123-
- `@nuxtjs/style-resources`;
124-
- `nuxt-purgecss`;
125-
- `@vue-storefront/nuxt-theme`;
126-
- `vue-lazy-hydration`;
127-
128-
### Libraries
129-
130-
- [`@storefront-ui/vue`](https://storefrontui.io);
131-
- [`vee-validate`](https://vee-validate.logaretm.com/v3);
132-
- [`lodash`](https://lodash.com/);
39.4 KB
Loading
-61.4 KB
Binary file not shown.

packages/core/docs/integrate/integration-guide.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Integrating eCommerce platform
1+
# Integrating e-commerce platform
22

33
:::danger Don't forget to reload the application
44
The application does not reload automatically after saving the changes in Server Middleware. Due to this, you have to restart the application manually. We are working on enabling Hot Reloading in future updates.
@@ -10,7 +10,7 @@ If you want to integrate with Vue Storefront, don't hesitate to get in touch wit
1010

1111
## Introduction
1212

13-
Integrating an eCommerce platform with Vue Storefront sounds scary. Luckily, many of our partners and community members with different seniority levels have successfully done it. We are sure that even without prior experience with Vue Storefront, you can too.
13+
Integrating an e-commerce platform with Vue Storefront sounds scary. Luckily, many of our partners and community members with different seniority levels have successfully done it. We are sure that even without prior experience with Vue Storefront, you can too.
1414

1515
This document will guide you through the process of creating integration and explain the concepts behind Vue Storefront.
1616

@@ -25,7 +25,7 @@ Before we get started, make sure that:
2525

2626
## Project structure
2727

28-
To make it easy to get started, we created an [eCommerce integration boilerplate](https://github.com/vuestorefront/ecommerce-integration-boilerplate).
28+
To make it easy to get started, we created an [e-commerce integration boilerplate](https://github.com/vuestorefront/ecommerce-integration-boilerplate).
2929

3030
It's a monorepo, which is a single repository containing multiple related projects. Each directory inside `packages` contains one project. There are three projects:
3131

@@ -35,7 +35,7 @@ It's a monorepo, which is a single repository containing multiple related projec
3535

3636
### API client
3737

38-
`api-client` is the **_server layer_** that extends our [Server Middleware](../architecture/server-middleware.html). It creates an API client (like `Apollo` for GraphQL or `Axios` for plain HTTP) that communicates with your eCommerce platform. It acts as a proxy between the users and the platform.
38+
`api-client` is the **_server layer_** that extends our [Server Middleware](../architecture/server-middleware.html). It creates an API client (like `Apollo` for GraphQL or `Axios` for plain HTTP) that communicates with your e-commerce platform. It acts as a proxy between the users and the platform.
3939

4040
Here, you will create new endpoints that accept parameters sent from the frontend and use them to fetch or submit data to the platform.
4141

@@ -78,7 +78,7 @@ API of your platform should have endpoints for most of these operations unless s
7878

7979
### Fork boilerplate repository
8080

81-
Now that we explained the basics, let's start creating an integration. Open the [eCommerce integration boilerplate repository](https://github.com/vuestorefront/ecommerce-integration-boilerplate) and click the `Use this template` button. This creates a copy of a repository and allows you to make changes without affecting the original project. Enter the name of the new repository and click `Create repository from template`.
81+
Now that we explained the basics, let's start creating an integration. Open the [e-commerce integration boilerplate repository](https://github.com/vuestorefront/ecommerce-integration-boilerplate) and click the `Use this template` button. This creates a copy of a repository and allows you to make changes without affecting the original project. Enter the name of the new repository and click `Create repository from template`.
8282

8383
Once the new repository is ready, clone it locally.
8484

@@ -106,7 +106,7 @@ Since we are mocking all functionalities in the boilerplate, different parts of
106106

107107
## Connect to the platform
108108

109-
Let's start by creating an API client that will communicate with the eCommerce platform. As mentioned above, the `api-client` does precisely that, so this is the project to update.
109+
Let's start by creating an API client that will communicate with the e-commerce platform. As mentioned above, the `api-client` does precisely that, so this is the project to update.
110110

111111
### Structure of the `api-client` project
112112

@@ -117,7 +117,7 @@ You will see only two files and one empty directory when you open the `packages/
117117

118118
### Add API client
119119

120-
API client is a library that handles sending requests to the eCommerce platform and parsing its responses.
120+
API client is a library that handles sending requests to the e-commerce platform and parsing its responses.
121121

122122
:::warning
123123
Examples below use `axios` to handle HTTP requests. However, you can use other libraries if your platform uses GraphQL or has dedicated clients.
@@ -164,7 +164,7 @@ module.exports = {
164164
location: '@sloth/api/server', // name of your api-client package followed by `/server`
165165
configuration: {
166166
api: {
167-
url: '' // URL of your eCommerce platform
167+
url: '' // URL of your e-commerce platform
168168
}
169169
}
170170
}
@@ -246,7 +246,7 @@ As mentioned in [Project structure](#project-structure) section, `api-client` is
246246
While this might be true for simple scenarios, it doesn't scale well. Some of the benefits of using such proxy are:
247247

248248
- **Caching** - selected responses can be cached to improve the performance significantly. While it's possible to do caching in the browser, each customer would have to make at least one request to a given endpoint.
249-
- **Lower cost** - when responses are cached, fewer requests are sent to the eCommerce platform. Depending on the provider, it might reduce the cost.
249+
- **Lower cost** - when responses are cached, fewer requests are sent to the e-commerce platform. Depending on the provider, it might reduce the cost.
250250
- **Smaller bundle** - with all the clients installed and configured on the server, the final bundle sent to the browsers can be much smaller. This is especially true for APIs based on GraphQL.
251251
- **Security** - API configuration, secrets, and keys are stored on the server and are not sent to the browser.
252252

0 commit comments

Comments
 (0)