I am running a magento 2.2.5 CE in production mode with two storefronts setup.
The settings in admin are as follows:
- Minify Html: Yes 
- Merge JavaScript Files: Yes 
- Enable JavaScript Bundling: Yes
- Minify JavaScript Files: Yes 
- Merge CSS Files: Yes 
- Minify CSS Files: Yes
Nothing is being minified, not the CSS, JS or HTML. The JS and CSS are atleast bundled into a single merged file, but with no minification.
All caches have been cleared and static files deployed probably a 1000 times since we've set the minification to true.
I've tried setting everything VIA CLI also and we are running in production so everything should be minified, but is not.
Please let me know if there's anything else I can try to get the default magento 2 minification to work.
- 
 Did you check settings for different store views and for default ?BartZalas– BartZalas2018年11月29日 22:31:23 +00:00Commented Nov 29, 2018 at 22:31
- 
 @BartZalas Yes, all settings are set to minify in all scopes.Jako Basson– Jako Basson2018年11月30日 15:11:49 +00:00Commented Nov 30, 2018 at 15:11
3 Answers 3
After a lot of struggling with this, i've finally found the issue.
I dived into the magento 2 source code to try and decipher how it decides when to minify files.
I discovered that even though our magento mode was set to production in the ENV file, the mode inside the vendor/magento/framework/App/State.php file still returned developer for some reason.
After going through the stack trace i finally found that we have a MAGE_MODE declaration set to developer inside our .htaccess file. As soon as I changed this to production, the minification started working (remember to restart apache to read the modified .htaccess file).
In conclusion, if anyone else faces this issue, make sure you are not setting the MAGE_MODE variable to developer inside your .htaccess file. Even if you override this value in all other sections of magento 2, some parts of magento 2 will still initialize under developer mode.
NOTE for NGINX users
You'll need to add it to your config as NGINX doesn't read .htaccess files. fastcgi_param MAGE_MODE production; Or, better yet, omit it entirely and set it via bin/magento deploy:mode:set production.
Thanks @kirkmadera for the NGINX comment.
Hope this saves someone out there some time.
- 
 I found also this command for example to minify css : php -f bin/magento config:set dev/css/minify_files 1 reference: devdocs.magento.com/guides/v2.3/frontend-dev-guide/themes/…BartZalas– BartZalas2018年12月20日 00:21:34 +00:00Commented Dec 20, 2018 at 0:21
- 
 I am using nginx, and I have the same problem as you. I have Magento 2.3.1, any suggestions on how to solve this problem?Despotars– Despotars2019年11月04日 08:41:23 +00:00Commented Nov 4, 2019 at 8:41
- 
 @Despotars You can try to follow the steps explained in the answer. Make sure MAGE_MODE is set to production in your root .htaccess file.Jako Basson– Jako Basson2019年11月04日 17:37:11 +00:00Commented Nov 4, 2019 at 17:37
- 
 2For NGINX, you'll need to add it to your config as NGINX doesn't read .htaccess files. fastcgi_param MAGE_MODE production; Or, better yet, omit it entirely and set it via bin/magento deploy:mode:set production. It can be very confusing to have bin/magento deploy:mode:show show production, when in reality, your site is running in developer or default mode because of an Nginx or htaccess setting.kirkmadera– kirkmadera2019年11月14日 02:13:04 +00:00Commented Nov 14, 2019 at 2:13
- 
 @kirkmadera gotcha. I'll modify the answer to include this. Thanks!Jako Basson– Jako Basson2019年11月15日 19:15:33 +00:00Commented Nov 15, 2019 at 19:15
For me, JS and CSS minification is not working in the production mode. I did the below steps and it is working for me.
php bin/magento config:set dev/js/minify_files 1
php bin/magento config:set dev/css/minify_files 1
php bin/magento cache:clean config
rm -rf pub/static/*
php bin/magento setup:static-content:deploy
The main thing is we need to flush the Magento config cache after enabling minification. If you directly change the value in the database, don't forget to clear the config cache.
After waisting days looking for the answer, it turns out that one of the configuration via admin wasn't working when I set it to yes in all options related to minify javaScript, after manually updating it in the DB started to correctly generate the .min.js files.
- First check your root .htaccess and verify that you have production mode se to "SetEnv MAGE_MODE production" 
- In your DB under the table "core_config_data" search for "path" that has minify on it - path LIKE "%minify%"
make sure all of them are in value 1 (dev/js/minify_files, dev/css/minify_files, dev/js/minify_files, dev/template/minify_html)
After that just do this commands
rm -rf var/{cache,di,generation,page_cache,view_preprocessed}
php bin/magento setup:static-content:deploy
Now you shouldn't have any problems with .min files