|
1 | 1 | ---
|
2 | 2 | layout: default
|
3 | 3 | group: fedg
|
4 |
| -subgroup: D_CSS_G |
5 | 4 | title: Simple style changes with client-side LESS compilation vs. server-side
|
6 |
| -menu_title: Simple style changes with client-side LESS compilation vs. server-side |
7 |
| -menu_order: 2 |
8 | 5 | version: 2.1
|
9 | 6 | github_link: frontend-dev-guide/css-guide/css_quick_guide_mode.md
|
10 | 7 | functional_areas:
|
11 | 8 | - Frontend
|
12 | 9 | ---
|
13 |
| -<h2> What's in this topic </h2> |
14 | 10 |
|
15 |
| -After you <a href="{{page.baseurl}}/frontend-dev-guide/themes/theme-create.html" target="_blank">create a theme</a>, before starting to change the styles, is deciding, which LESS compilation mode you will use. There are <a href="{{page.baseurl}}/frontend-dev-guide/css-topics/css-preprocess.html#LESS compilation modes" target="_blank">two modes available in Magento</a>: server-side compilation mode and client-side (recommended for {% glossarytooltip d2093e4a-2b71-48a3-99b7-b32af7158019 %}theme{% endglossarytooltip %} development). |
16 |
| -This topic demonstrates on a practical example how the choice of the mode influences the styles development. |
| 11 | +After you [create a theme]({{page.baseurl}}/frontend-dev-guide/themes/theme-create.html), you need to decide which LESS compilation mode to use before changing styles. You can choose between [two modes]({{page.baseurl}}/frontend-dev-guide/css-topics/css-preprocess.html#LESS compilation modes): |
17 | 12 |
|
18 |
| -The first step, creating and applying a theme is done before the compilation mode is chosen, so it is described only once, but is required whatever compilation mode you will further use. |
| 13 | +- Server-side compilation mode (default) |
| 14 | +- Client-side compilation mode (recommended for {% glossarytooltip d2093e4a-2b71-48a3-99b7-b32af7158019 %}theme{% endglossarytooltip %} development) |
19 | 15 |
|
20 |
| -In the examples in this topic the <a href="{{page.baseurl}}/frontend-dev-guide/css-guide/css_quick_guide_approach.html#simple_extend">simplest approach for customizing theme styles</a> is used: changes are done in the `_extend.less` of the new theme. |
| 16 | +The examples in this topic use the [simple approach]({{page.baseurl}}/frontend-dev-guide/css-guide/css_quick_guide_approach.html#simple_extend) for customizing theme styles. You make changes to the `_extend.less` file. |
21 | 17 |
|
22 |
| -In our examples we will change the color and font of the primary buttons. The default view of the primary buttons can be illustrated by the **Create an Account** button view on the Customer login page: |
| 18 | +In our examples, we will change the color and font of the primary buttons. The default view of the primary buttons can be illustrated by the **Create an Account** button view on the Customer login page: |
23 | 19 |
|
24 |
| -<img src="{{site.baseurl}}/common/images/extend_less_screenshot0.png" alt="Admin login page with the default view of the primary buttons"> |
| 20 | + |
25 | 21 |
|
26 |
| -<h2 id="first_step">First step: Create and apply a theme</h2> |
| 22 | +## Before you begin |
27 | 23 |
|
28 |
| -1. Create a new theme as described in the <a href="{{page.baseurl}}/frontend-dev-guide/themes/theme-create.html" target="_blank">Create a theme</a> topic. In your `theme.xml` specify Magento Luma or Magento Blank as a parent theme. |
29 |
| -2. <a href="{{page.baseurl}}/frontend-dev-guide/themes/theme-apply.html#theme-apply-apply">Apply your theme</a> in the {% glossarytooltip 18b930cf-09cc-47c9-a5e5-905f86c43f81 %}Magento Admin{% endglossarytooltip %}. |
| 24 | +1. [Create a theme]({{page.baseurl}}/frontend-dev-guide/themes/theme-create.html). In your `theme.xml` file, specify Magento Luma or Magento Blank as the parent theme. |
| 25 | +2. [Apply your theme]({{page.baseurl}}/frontend-dev-guide/themes/theme-apply.html#theme-apply-apply) in the {% glossarytooltip 18b930cf-09cc-47c9-a5e5-905f86c43f81 %}Magento Admin{% endglossarytooltip %}. |
30 | 26 |
|
31 |
| -Server-side is the default mode for LESS compilation, so if you do not change this, your Magento instance is using server-side compilation mode. |
32 |
| - |
33 |
| -<h2 id="server-side">Making simple style changes in server-side compilation mode</h2> |
| 27 | +## Using server-side compilation mode |
34 | 28 |
|
35 | 29 | The following is an illustration of how the process of making simple changes looks like with the server-side LESS compilation mode:
|
36 |
| -<ol> |
37 |
| -<li>Create and apply a theme.</li> |
38 |
| -<li>In your theme directory, add <code>web/css/source/_extend.less</code>.</li> |
39 |
| -<li>Change the color of the buttons by adding the following code in <code>_extend.less</code>: |
40 |
| - |
41 |
| -<img src="{{ site.baseurl}}/common/images/extend_less_code_1.png" alt="Less code redefining the color of the primary buttons"> |
42 |
| -</li> |
43 |
| -<li markdown="1">[Clean static files cache]({{page.baseurl}}/howdoi/clean_static_cache.html)</li> |
44 |
| -<li>Refresh the page, and view the changes applied. For example: |
45 |
| - |
46 |
| -<img src="{{ site.baseurl}}/common/images/extend_less_screenshot1.png" alt="Less code redefining the color of the primary buttons"> |
47 |
| -</li> |
48 |
| -<li>Change the font of the buttons by adding the following code in <code>_extend.less</code>: |
49 |
| - |
50 |
| -<img src="{{ site.baseurl}}/common/images/extend_less_code_2.png" alt="Less code redefining the font of the primary buttons"> |
51 |
| -</li> |
52 |
| -<li>Delete all files in the following directories: |
53 |
| -<ul> |
54 |
| -<li><code>pub/static/frontend/<Your_Vendor>/<your_theme></code></li> |
55 |
| -<li><code>var/view_preprocessed/less</code> </li> |
56 |
| -</ul> |
57 |
| -</li> |
58 |
| -<li>Refresh the page, and view the changes applied. |
59 |
| - |
60 |
| -<img src="{{ site.baseurl}}/common/images/extend_less_screenshot2.png" alt="Admin login page where the font of the buttons was changed"> |
61 |
| -</li> |
62 |
| -</ol> |
63 |
| - |
64 |
| -If your Magento instance uses the server-side compilation mode, to make your changes apply, you need to clean the previously generated static view files. Several ways to do this are described in the [Clean static files cache]({{page.baseurl}}/howdoi/clean_static_cache.html) topic. You can automate this process by additionally installing Grunt, and using the built-in Grunt commands to watch the changes and clean the directories. The flow of making changes using Grunt is described in the following section. |
65 |
| - |
66 |
| -<h2 id="server-side-grunt">Making simple style changes in server-side compilation mode using Grunt</h2> |
67 |
| - |
68 |
| -<ol> |
69 |
| -<li>Create and apply a theme. </li> |
70 |
| -<li>In your theme directory, add <code>web/css/source/_extend.less</code>.</li> |
71 |
| -<li>Install Grunt and register your theme as described in <a href="{{page.baseurl}}/frontend-dev-guide/css-topics/css_debug.html#grunt_prereq" target="_blank">Installing and configuring Grunt</a>.</li> |
72 |
| -<li>From your Magento installation directory, run the following commands: |
73 |
| -<ul> |
74 |
| -<li><code>grunt exec:<your_theme></code></li> |
75 |
| -<li><code>grunt less:<your_theme></code></li> |
76 |
| -<li><code>grunt watch</code></li> |
77 |
| -</ul> |
78 |
| -Where <code><your_theme></code> is the code of your theme. Conventionally it should coincide with the theme directory name. |
79 |
| -</li> |
80 |
| -<li>Change the color of the buttons by adding the following code in <code>_extend.less</code>: |
81 |
| -<img src="{{ site.baseurl}}/common/images/extend_less_code_1.png" alt="Less code redefining the color of the primary buttons"> |
82 |
| -</li> |
83 |
| -<li>Refresh the page and view your changes applied: |
84 |
| -<img src="{{ site.baseurl}}/common/images/extend_less_screenshot1.png" alt="Admin login page where the color of the button was changed"> |
85 |
| -</li> |
86 |
| -<li>Change the font of the buttons by adding the following code in <code>_extend.less</code>: |
87 |
| -<img src="{{ site.baseurl}}/common/images/extend_less_code_2.png" alt="Less code redefining the font of the primary buttons"> |
88 |
| -</li> |
89 |
| -<li>Refresh the page and view your changes applied: |
90 |
| -<img src="{{ site.baseurl}}/common/images/extend_less_screenshot2.png" alt="Admin login page where the font of the buttons was changed"> |
91 |
| -</li> |
92 |
| -</ol> |
93 |
| - |
94 |
| -<h2 id="client-side">Making simple style changes in client-side compilation mode</h2> |
95 |
| - |
96 |
| -<ol> |
97 |
| -<li>Create and apply a theme.</li> |
98 |
| -<li>In your theme directory, add <code>web/css/source/_extend.less</code>.</li> |
99 |
| -<li>In the Magento Admin, change the LESS compilation mode to client-side under <b>STORES</b> > <b>Configuration</b> > <b>ADVANCED</b> > <b>Developer</b> > <b>Front-end development workflow</b> > <b>Workflow type</b>. For detailed description see the <a href="{{page.baseurl}}/frontend-dev-guide/css-topics/css-preprocess.html#less_modes">CSS preprocessing</a> topic.</li> |
100 |
| -<li markdown="1">[Clean static files cache]({{page.baseurl}}/howdoi/clean_static_cache.html) |
101 |
| -</li> |
102 |
| -<li>Change the color of the buttons by adding the following code in <code>_extend.less</code>: |
103 |
| - |
104 |
| -<img src="{{ site.baseurl}}/common/images/extend_less_code_1.png" alt="Less code redefining the color of the primary buttons"> |
105 |
| -</li> |
106 |
| -<li>Refresh the page and view your changes applied: |
107 |
| - |
108 |
| -<img src="{{ site.baseurl}}/common/images/extend_less_screenshot1.png" alt="Admin login page where the font of the buttons was changed"> |
109 |
| -</li> |
110 |
| -<li>Change the font of the buttons by adding the following code in <code>_extend.less</code>: |
111 |
| - |
112 |
| -<img src="{{ site.baseurl}}/common/images/extend_less_code_2.png" alt="Less code redefining the font of the primary buttons"> |
113 |
| -</li> |
114 |
| -<li>Refresh the page and view your changes applied: |
115 |
| - |
116 |
| -<img src="{{ site.baseurl}}/common/images/extend_less_screenshot2.png" alt="Admin login page where the font of the buttons was changed"> |
117 |
| -</li> |
118 |
| -</ol> |
119 |
| - |
120 |
| -If your Magento instance uses the client-side compilation mode, simple changes are applied at once. In case of more sophisticated changes, you might need to manually clean the theme sub-directory in the <code>pub/static/frontend</code> directory. There are more details about these types of changes and about the client-side mode implementation in the <a href="{{page.baseurl}}/frontend-dev-guide/css-topics/css_debug.html#css_debug_client" target="_blank">Styles debugging</a> topic. |
121 |
| - |
122 |
| -<h2>Recommended reading</h2> |
123 |
| -<ul> |
124 |
| -<li><a href="{{page.baseurl}}/frontend-dev-guide/css-topics/css_debug.html" target="_blank">Styles debugging</a></li> |
125 |
| -<li><a href="{{page.baseurl}}/frontend-dev-guide/css-topics/css-preprocess.html" target="_blank">CSS preprocessing</a></li> |
126 |
| -</ul> |
| 30 | + |
| 31 | +1. Navigate to your theme directory and add the `web/css/source/_extend.less` file. |
| 32 | +1. Change the color of the buttons by adding the following code in the `_extend.less` file: |
| 33 | + |
| 34 | + ```css |
| 35 | + .action { |
| 36 | + &.primary { |
| 37 | + background-color: palevioletred; |
| 38 | + border-color: palevioletred; |
| 39 | + } |
| 40 | + } |
| 41 | + ``` |
| 42 | + |
| 43 | +1. [Clean static files cache]({{page.baseurl}}/howdoi/clean_static_cache.html). |
| 44 | +1. Refresh the page and verify your changes. |
| 45 | + |
| 46 | +  |
| 47 | + |
| 48 | +1. Change the button font by adding the following code in the `_extend.less` file: |
| 49 | + |
| 50 | + ```css |
| 51 | + .action { |
| 52 | + &.primary { |
| 53 | + background-color: palevioletred; |
| 54 | + border-color: palevioletred; |
| 55 | + font-size: 1.5em; |
| 56 | + } |
| 57 | + } |
| 58 | + ``` |
| 59 | + |
| 60 | +1. Delete all files in the following directories: |
| 61 | + |
| 62 | + - `pub/static/frontend/<vendor>/<theme>` |
| 63 | + - `var/view_preprocessed/css` |
| 64 | + - `var/view_preprocessed/source` |
| 65 | + |
| 66 | +1. Refresh the page and verify your changes. |
| 67 | + |
| 68 | +  |
| 69 | + |
| 70 | +{:.bs-callout .bs-callout-info} |
| 71 | +If you are using server-side compilation mode, you must [clean generated static view files]({{page.baseurl}}/howdoi/clean_static_cache.html). Continue to the next section to learn how to use Grunt to automate this process. |
| 72 | + |
| 73 | +## Using server-side compilation mode with Grunt |
| 74 | + |
| 75 | +1. Navigate to your theme directory and create a `web/css/source/_extend.less` file. |
| 76 | +1. Install Grunt and register your theme as described in [Installing and configuring Grunt]({{page.baseurl}}/frontend-dev-guide/css-topics/css_debug.html#grunt_prereq). |
| 77 | +1. From your Magento installation directory, run the following commands: |
| 78 | + |
| 79 | + - `grunt exec:<your_theme>` |
| 80 | + - `grunt less:<your_theme>` |
| 81 | + - `grunt watch` |
| 82 | + |
| 83 | +1. Change the color of the buttons by adding the following code in the `_extend.less` file: |
| 84 | + |
| 85 | + ```css |
| 86 | + .action { |
| 87 | + &.primary { |
| 88 | + background-color: palevioletred; |
| 89 | + border-color: palevioletred; |
| 90 | + } |
| 91 | + } |
| 92 | + ``` |
| 93 | + |
| 94 | +1. Refresh the page and verify your changes. |
| 95 | + |
| 96 | +  |
| 97 | + |
| 98 | +1. Change the button font by adding the following code in the `_extend.less` file: |
| 99 | + |
| 100 | + ```css |
| 101 | + .action { |
| 102 | + &.primary { |
| 103 | + background-color: palevioletred; |
| 104 | + border-color: palevioletred; |
| 105 | + font-size: 1.5em; |
| 106 | + } |
| 107 | + } |
| 108 | + ``` |
| 109 | + |
| 110 | +1. Refresh the page and verify your changes. |
| 111 | + |
| 112 | +  |
| 113 | + |
| 114 | +## Using client-side compilation mode |
| 115 | + |
| 116 | +1. Navigate to your theme directory and create a `web/css/source/_extend.less` file. |
| 117 | +1. Log in to the Magento Admin. |
| 118 | +1. Click **STORES** > **Configuration** > **ADVANCED** > **Developer** > **Front-end development workflow** > **Workflow type**. |
| 119 | +1. Change the LESS compilation mode to client-side. |
| 120 | +1. [Clean static view files]({{page.baseurl}}/howdoi/clean_static_cache.html). |
| 121 | +1. Change the color of the buttons by adding the following code in the `_extend.less` file: |
| 122 | + |
| 123 | + ```css |
| 124 | + .action { |
| 125 | + &.primary { |
| 126 | + background-color: palevioletred; |
| 127 | + border-color: palevioletred; |
| 128 | + } |
| 129 | + } |
| 130 | + ``` |
| 131 | + |
| 132 | +1. Refresh the page and verify your changes. |
| 133 | + |
| 134 | +  |
| 135 | + |
| 136 | +1. Change the button font by adding the following code in the `_extend.less` file: |
| 137 | + |
| 138 | + ```css |
| 139 | + .action { |
| 140 | + &.primary { |
| 141 | + background-color: palevioletred; |
| 142 | + border-color: palevioletred; |
| 143 | + font-size: 1.5em; |
| 144 | + } |
| 145 | + } |
| 146 | + ``` |
| 147 | + |
| 148 | +1. Refresh the page and verify your changes. |
| 149 | + |
| 150 | +  |
| 151 | + |
| 152 | +{:.bs-callout .bs-callout-info} |
| 153 | +Simple changes are applied immediately in client-side compilation mode. For more sophisticated changes, you might need to manually clean the theme sub-directory in the `pub/static/frontend` directory. See [Styles debugging]({{page.baseurl}}/frontend-dev-guide/css-topics/css_debug.html#css_debug_client). |
0 commit comments