1

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.

Greg
2,7495 gold badges42 silver badges89 bronze badges
asked Sep 28, 2018 at 3:31

3 Answers 3

0

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

answered Sep 28, 2018 at 12:16
1
  • 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 . Commented Sep 28, 2018 at 22:07
0

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
answered Sep 28, 2018 at 12:17
14
  • 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 . Commented Sep 28, 2018 at 22:07
  • Please post your error message and file name in the question. Commented Sep 29, 2018 at 4:46
  • there is no way to minify js without debuging the error ? Commented Sep 29, 2018 at 18:08
  • How can we help until you show us your error. Commented Sep 29, 2018 at 19:36
  • prntscr.com/l09ptk Commented Sep 29, 2018 at 20:21
0

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.

Pang
1371 silver badge6 bronze badges
answered Sep 28, 2018 at 10:22
1
  • 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 . Commented Sep 28, 2018 at 22:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.