how to minify js files in order via grunt-contrib-uglify?

后端 未结 9 2126
执念已碎
执念已碎 2021-02-01 14:51

I have a directory like below:

/folder/b.js
/folder/jQuery.js
/folder/a.js
/folder/sub/c.js

I want to minify all these js files in one js file

9条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-01 15:28

    Looks like the second part of your question is still unanswered. But let me try one by one.

    Firstly you can join and uglify a large number of js files into one as explained by the concat answer earlier. It should also be possible to use https://github.com/gruntjs/grunt-contrib-uglify because it does seem to have wildcards. You may have to experiment with 'expand = true' option and wildcards. That takes care of your first question.

    For the second part, say you joined and uglified into big-ugly.js

    Now in your html you can add following directives:

    
    
    
     
    
    
    

    And then pass it through the grunt html preprocessor at https://www.npmjs.com/package/grunt-processhtml as part of your grunt jobs.

    This preprocessor will replace the entire block with

    
    

    Which means that the html file with be semantically equivalent - before and after the grunt jobs; i.e. if the page works correctly in the native form (for debugging) - then the transformed page must work correctly after the grunt - without requiring you to manually change any tags.

提交回复
热议问题