|
1 | 1 | # Magento 2 Gulp Integration
|
2 | 2 |
|
3 |
| -<p>As a Magento 2 frontend developer you might have noticed that less to css compilation process is slow with grunt and it takes more time to rebuild everything making you an inefficient developer. </p> |
| 3 | +As a Magento 2 frontend developer you might have noticed that less to css compilation process is slow with grunt and it |
| 4 | +takes more time to rebuild everything making you an inefficient developer. |
4 | 5 |
|
5 |
| -<p>However, you could solve this problem with Gulp. Gulp is a task / build runner which uses Node.js for web development. The main difference between Gulp and Grunt lies in how they deal with their automation tasks inside. </p> |
| 6 | +However, you could solve this problem with Gulp. Gulp is a task / build runner which uses Node.js for web development. |
| 7 | +The main difference between Gulp and Grunt lies in how they deal with their automation tasks inside. |
6 | 8 |
|
7 |
| -<p>Gulp uses Node Stream while Grunt uses temp files. Therefore, Gulp compilation is faster compared to Grunt. </p> |
| 9 | +Gulp uses Node Stream while Grunt uses temp files. Therefore, Gulp compilation is faster compared to Grunt. |
8 | 10 |
|
| 11 | +## Comparing with Grunt |
9 | 12 |
|
10 |
| -<h2>Comparing with Grunt</h2> |
11 | 13 | <table>
|
12 | 14 | <tr><th></th><th>Gulp</th><th>Grunt</th></tr>
|
13 | 15 | <tr><td>Compilation of all themes (10 files):</td><td>16sec</td><td>33sec</td></tr>
|
14 | 16 | <tr><td>Custom theme compilation (2 files)</td><td>4.5s</td><td>11.2s</td></tr>
|
15 | 17 | </table>
|
16 | 18 |
|
17 |
| -<h2>Installation</h2> |
| 19 | +## Installation |
18 | 20 |
|
19 |
| -1. Download as a zip file or clone this in to ur pc. |
| 21 | +### Method 1: Install using composer (only for Magento >= 2.2.2) |
20 | 22 |
|
21 |
| -2. Copy "gulpfile.js" and "package.json" in to the root directory (code pool) |
| 23 | +1. Ensure Node is used in Version 11: `nvm install v11` |
22 | 24 |
|
23 |
| -2.2. If you are using Magento 2.2.1 or lower comment line number 47 - 48 |
| 25 | +2. Add the composer repository `composer config repositories.gulp vcs https://github.com/subodha/magento-2-gulp.git` |
| 26 | + |
| 27 | +3. Install the module `composer require subodha/magento-2-gulp:"1.*"` |
| 28 | + |
| 29 | +4. Add these scripts to your composer.json: |
| 30 | + |
| 31 | +```json |
| 32 | +{ |
| 33 | + "scripts": { |
| 34 | + "post-update-cmd": [ |
| 35 | + "cd vendor/subodha/magento-2-gulp && npm install" |
| 36 | + ], |
| 37 | + "post-install-cmd": [ |
| 38 | + "cd vendor/subodha/magento-2-gulp && npm install" |
| 39 | + ] |
| 40 | + } |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +5. Run `composer install` |
| 45 | + |
| 46 | +6. Define your theme configuration in `dev/tools/grunt/configs/themes.js` |
| 47 | + |
| 48 | +7. You can now run `vendor/bin/gulpm2 build --your_theme` to compile your styles |
| 49 | + |
| 50 | +### Method 2: Copying to your Magento installation (old method for Magento <= 2.2.1) |
| 51 | + |
| 52 | +1. Download as a zip file or clone this repository. |
| 53 | + |
| 54 | +2. Copy "gulpfile.js" and "package.json" in to the root directory (code pool). |
| 55 | + |
| 56 | + If you are using Magento 2.2.1 or lower comment line number 47 - 48. |
24 | 57 |
|
25 | 58 | 3. Install node.js for your OS: https://nodejs.org/en/
|
26 | 59 |
|
27 |
| -4. Install gulp globally using <code>npm install -g gulp-cli</code> |
| 60 | +4. Install gulp globally using `npm install -g gulp-cli` |
28 | 61 |
|
29 | 62 | 5. Install modules: run a command in a root directory of your project "npm install".
|
30 |
| - <br>(If you already installed Grunt please remove node_module directory) |
31 | 63 |
|
32 |
| -<h2>How to run</h2> |
| 64 | + (If you already installed Grunt please remove node_module directory) |
33 | 65 |
|
34 |
| -1. Run <code>gulp exec --theme</code> ex: gulp exec --luma |
35 |
| - <br>Or: <code>php bin/magento dev:source-theme:deploy --locale="en_AU" --area="frontend" <br>--theme=" |
36 |
| - VendorName/themeName"</code> |
| 66 | +## How to run |
37 | 67 |
|
38 |
| -2. Run : <code>gulp deploy --theme</code> ex: gulp deploy --luma |
39 |
| - <br>Or: <code>php bin/magento setup:static-content:deploy en_AU</code> |
| 68 | +1. Run `gulp exec --theme` ex: `gulp exec --luma` |
| 69 | + <br>Or: `php bin/magento dev:source-theme:deploy --locale="en_AU" --area="frontend" <br>--theme=" |
| 70 | + VendorName/themeName"` |
| 71 | + |
| 72 | +2. Run : `gulp deploy --theme` ex: `gulp deploy --luma` |
| 73 | + <br>Or: `php bin/magento setup:static-content:deploy en_AU` |
40 | 74 |
|
41 | 75 | 3. Run gulp command in the root directory with arguments or without. Examples:<br>
|
42 |
| - 3.a. Compilation of all themes: <code>gulp</code><br> |
43 |
| - 3.b. Compilation of certain theme: <code>gulp less --luma</code><br> |
44 |
| - 3.c. Watcher of certain theme: <code>gulp watch --luma</code><br> |
45 |
| - 3.d. Compilation of certain theme with minification (+~2.5s): <code>gulp less --luma --min</code><br> |
46 |
| - 3.e. Compilation of certain theme with sourcemap(+~1.5s), can't be used with minification: <code>gulp less --luma |
47 |
| - --map</code><br> |
48 |
| - 3.f. Compilation with live reload: <code>gulp less --luma --live</code><br> |
49 |
| - 3.g. Watcher with liveReload: <code>gulp watch --luma --live</code><br> |
50 |
| - 3.h. For clear the magento cache: <code>gulp cache-flush</code><br> |
| 76 | + 3.a. Compilation of all themes: `gulp`<br> |
| 77 | + 3.b. Compilation of certain theme: `gulp less --luma`<br> |
| 78 | + 3.c. Watcher of certain theme: `gulp watch --luma`<br> |
| 79 | + 3.d. Compilation of certain theme with minification (+~2.5s): `gulp less --luma --min`<br> |
| 80 | + 3.e. Compilation of certain theme with sourcemap(+~1.5s), can't be used with |
| 81 | + minification: `gulp less --luma --map`<br> |
| 82 | + 3.f. Compilation with live reload: `gulp less --luma --live`<br> |
| 83 | + 3.g. Watcher with liveReload: `gulp watch --luma --live`<br> |
| 84 | + 3.h. For clear the magento cache: `gulp cache-flush`<br> |
51 | 85 |
|
52 | 86 | 4. For using liveReload install extension for your browser: https://livereload.com/
|
53 | 87 | <br>4.a. Turn on the extension on the page of project.
|
54 | 88 |
|
55 |
| -5. For clear the magento cache: gulp cache-flush |
56 |
| -6. For clear the magento static files cache: gulp clean --luma |
| 89 | +5. For clear the magento cache: `gulp cache-flush` |
| 90 | +6. For clear the magento static files cache: `gulp clean --luma` |
| 91 | + |
| 92 | +### How to run (with composer integration) |
| 93 | + |
| 94 | +See above, but replace `gulp` with `vendor/bin/gulpm2`. |
0 commit comments