cancel
Showing results for 
Search instead for 
Did you mean: 

Skip Luma theme when compiling static resources

0 Kudos

Skip Luma theme when compiling static resources

Feature request from devdesco-ceo, posted on GitHub Jan 19, 2016

I have a situation where I have custom theme (Porto, based off blank theme) installed and active, and prepackaged Luma theme is not active anywhere in my Magento stores, so no need to trigger compilation on it. BWT when I run static content compiler, both Magento/blank, Magento/luma and Smartwave/porto are being compiled. That would be fine, but I am compiling 6 locales for my multistore/multilang setup, and that takes awhile, believe me!

The command I trigger: php ./bin/magento setup:static-content:deploy en_US fr_FR de_DE pt_PT es_ES it_IT

What can I do to pass a command to compiler to skip compilation of Magento/luma?

29 Comments
apiuser
New Member

Comment from antonkril, posted on GitHub Mar 08, 2016

@erikhansen, yes, we have this on roadmap, and yes, we would accept a PR. cc @buskamuza

apiuser
New Member

Comment from dimasch, posted on GitHub Mar 25, 2016

+1 for the solution.

apiuser
New Member

Comment from kirmorozov, posted on GitHub Mar 25, 2016

Just run in parallel for each store. This is trivial case.

apiuser
New Member

Comment from buskamuza, posted on GitHub May 31, 2016

Related internal ticket is MAGETWO-49510

apiuser
New Member

Comment from hostep, posted on GitHub Jun 01, 2016

There is an open pull request which will support this btw: https://github.com/magento/magento2/pull/4294

apiuser
New Member

Comment from thdoan, posted on GitHub Jun 28, 2016

For those who cannot wait for @denisristic's PR to be rolled into v2.2, then you can merge the two diffs below for a quick fix (based on v2.0.7).

File .../vendor/magento/module-deploy/Model/Deployer.php Deployer.php.diff.txt Deployer.php.txt (merged)

File .../vendor/magento/module-deploy/Console/Command/DeployStaticContentCommand.php

DeployStaticContentCommand.php.diff.txt DeployStaticContentCommand.php.txt (merged)

This change allows you to pass --theme=<theme> or -t <theme> to setup:static-content:deploy to deploy files only for the theme you specify. Example: magento setup:static-content:deploy --theme=luma

apiuser
New Member

Comment from denisristic, posted on GitHub Jun 28, 2016

@thdoan thanks for diff patch Smiley Happy

In the latest version you can exclude theme by adding flag --exclude-theme=THEME (since that is what @devdesco-ceo asked)

Also, as for themes there are added include/exclude flags for languages (--language and --exclude-language) and for areas (--area and --exclude-area)

apiuser
New Member

Comment from thdoan, posted on GitHub Jun 29, 2016

Even though deploying to one theme cut down on the deployment time by several orders of magnitude, even a 10-second static deployment time adds up over time. This wasn't working out very well for our rapid prototyping workflow, so I came up with a method to reduce the time to almost instantaneous. If you feel that this may also fit into your workflow, then proceed...

On a high level, it is quite simple: (1) find the most recently modified files, (2) copy only those files to their respective directories in pub/static. Here are the steps in more detail (this assumes that you are in developer mode):

  1. To find the most recently modified files, it's helpful if your code base resides inside a version control system, but not necessary. To give a specific example, let's say you modified the JavaScript file /path/to/magento/app/design/frontend/<Vendor>/<theme>/web/js/module.js. When you run magento setup:static-content:deploy, it copies the file to /path/to/magento/pub/static/frontend/<Vendor>/<theme>/<locale>/js. With this information in hand, we know that <theme>/web maps to <locale> under pub/static, so first cd to the web directory. From there, you can do git ls-files --modified --others to get a list of modified/new files relative to that directory. If you are not using Git, then there's likely an equivalent command (for example, in CVS this can be accomplished by doing something like cvs -nq update $1 | sed -n "s/^[?AMU] //p"; if you're not using version control at all, then you can get a list of files modified in the last hour by executing find * -type f -mmin -60 -print). You should see a plain list of file(s):

    js/module.js
  2. To copy the modified files into their respective static directories, pipe the list of files into xargs. Using the Git example from step 1, the command should now look like this:

    git ls-files --modified --others | xargs -I {} cp --parents {} /path/to/magento/pub/static/frontend/<Vendor>/<theme>/*/

    The --parents option creates the directory structure if necessary. The * glob takes care of matching whatever locale you're in.

To put it all together, you can wrap this up into a nice little alias, e.g.:

alias deploy='cd /path/to/magento/app/design/frontend/<Vendor>/<theme>/web; git ls-files --modified --others | xargs -I {} cp --parents {} /path/to/magento/pub/static/frontend/<Vendor>/<theme>/*/; cd - 1> /dev/null'

If you are managing multiple themes, then you can convert this into a bash function that accepts a themes param and loops through each theme to do the same.

baldwin_pieter
Core Contributor

Email me when someone replies