Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A faster route to deploying static content in Magento 2? Dev to Live etc?

This is my environment. Please note this is also set in the relevant development modes and production modes.

Dev: https://ar.dev.loc/ https://en.dev.loc/  Live: https://ar.site.com/ https://en.site.com/ 

I am using a multi store setup with Arabic and English and everything is working well including building modules and template building.

However, if I make a change to any less file or JS file (despite using grunt less or grunt watch) I have to run the following commands on my development environment everything single time to see them on my local machine.

$ rm -rf var/cache var/page_cache var/view_preprocessed pub/static $ mkdir pub/static $ bin/magento setup:static-content:deploy $ bin/magento setup:static-content:deploy ar_SA $ grunt exec less // sometimes I leave this do this $ grunt // I swap between these 

This takes a long time to do this process everytime. It is frustrating as I am fast coder and like to see CSS and Less immediately on the site and not wait around.

The quick approach what our team is doing is actually making changes in pub/static and then we ship these to less and app/design etc and then do the process above and then git.

Live server is pretty much the same. Git pull and then maintenance mode (madness on a live ecom site! Who build M2?? Then we run commands above - downtime of 45mins)

Surely there must be a quicker way for our deployment, development and team to work better and to see changes faster without downtime!

Even Magento 2 official documentation says your LIVE site needs to go into maintenance and downtime mode to publish content - this is not an option for us. The CTO are not happy. Simply absurd.

Related questions with people asking about faster development same issues:

Css changes reflect only after deploy command in magento2

Magento 2 static cache

Changes to CSS and JavaScript applies only after deploying static content

So I want to collate all the issues and resolve this.

like image 648
TheBlackBenzKid Avatar asked Jul 26 '16 11:07

TheBlackBenzKid


People also ask

What is static content deploy in Magento 2?

The static view files deployment command enables you to write static files to the Magento file system when the Magento software is set for production mode. The term static view file refers to the following: “Static” means it can be cached for a site (that is, the file is not dynamically generated).

What Yaml file is used to optimize and configure the Magento cloud build process?

magento. env. yaml —centralizes the management of build and deploy actions across all of your environments, including Pro Staging and Production, using environment variables.

Which of these files does fall under static view files?

Static View Files Deployment Overview Static part refers to the files that can be cached if not generated dynamically and view — to the Model-View-Controller layer. You can find the static view files in the /pub/static (contains js, css, html and others) or /var/view_preprocessed directory (contains phtml files).


1 Answers

yes it can be faster by following steps :

  1. Change in your js/css file in app directory
  2. Now Delete the file form pub/static folder

you can find the file in pub static by following command

find pub/static -iname yourjsfile.js 
  1. remove only that file in which you have changes from pub/static folder
  2. make sure that pub/static.htaccess file & pub/static.php file is there
  3. assign file write permissions to pub folder
  4. now hit the URL in browser .htaccess will directly deploy missing js file

.htaccess in pub/static send the missing files to pub/static.php with parameter resource and pub/static.php file creates an StaticResource for the file if available and deploy that.

Note: this only works with apache mod_rewrite

For Nginx you need to configure the same via nginx.conf.sample

like image 100
Emizen Tech Avatar answered Sep 20 '22 21:09

Emizen Tech