I have some code error due to upgrade in Magento 2 but my goal is to minify js. Till now I know that we can not minify js without correcting error of the code in magento but I want to know some trick some realy awesome trick to minify js even I have some issue in the code.
3 Answers 3
I think all that you need is enable "Enable JavaScript Bundling" and "Minify JavaScript Files" options in system configuration on website level in System Configuration > ADVANCED > Developer > JavaScript Settings section and redeploy static content
-
sorry i think you dont understand the question or maybe i didnt explain it correctly . when i minify js in developer mode and after i switch to production mode then js is not minified because there is some error in the code .. i dont want to remove the error i want to minify it only .Flutterer– Flutterer2018年09月28日 22:07:52 +00:00Commented Sep 28, 2018 at 22:07
Go to admin panel Stores -> Configuration -> Advanced -> Developer . You will find option to enable js minification, choose it to be Yes (This option will be visible only if your developer mode is enabled.) . In your Magento 2 ssh console run the below command to set production mode if it is not set, because minification works only in production mode:
bin/magento deploy:mode:set production --skip-compilation
Note: --skip-compilation command is not mandatory, use it if you want skip compilation, i would recommend you to not skip it. Then run the below commands:
bin/magento cache:clean
bin/magento setup:upgrade
bin/magento setup:static-content:deploy
-
sorry i think you dont understand the question or maybe i didnt explain it correctly . when i minify js in developer mode and after i switch to production mode then js is not minified because there is some error in the code .. i dont want to remove the error i want to minify it only .Flutterer– Flutterer2018年09月28日 22:07:42 +00:00Commented Sep 28, 2018 at 22:07
-
Please post your error message and file name in the question.Sourabh Kumar Sharma– Sourabh Kumar Sharma2018年09月29日 04:46:50 +00:00Commented Sep 29, 2018 at 4:46
-
there is no way to minify js without debuging the error ?Flutterer– Flutterer2018年09月29日 18:08:50 +00:00Commented Sep 29, 2018 at 18:08
-
How can we help until you show us your error.Sourabh Kumar Sharma– Sourabh Kumar Sharma2018年09月29日 19:36:42 +00:00Commented Sep 29, 2018 at 19:36
-
prntscr.com/l09ptkFlutterer– Flutterer2018年09月29日 20:21:37 +00:00Commented Sep 29, 2018 at 20:21
To merge JavaScript files in Magento 2:
Navigate to Admin panel> Stores> Configuration> Advanced> Developer
Open the JavaScript Settings section and in the Minify JavaScript Files field, select Yes.
When complete, click Save Config.
If the above solution is not working for you due to some bugs or errors, I would try this gulp solution
Take a look at this: How to minify/optimise Javascript on Magento 2?
Although, I would strongly recommend fixing the error.
-
ok i will think about removing the error but for now i am trying to minify it . if nothing helped me out then will do something like that .Flutterer– Flutterer2018年09月28日 22:09:04 +00:00Commented Sep 28, 2018 at 22:09