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

后端 未结 9 2036
执念已碎
执念已碎 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:21

    This might be only remotely related to your question but I wanted something similar. Only my order was important in the following way:

    I was loading all vendor files (angular, jquery, and their respective related plugins) with a wildcard (['vendor/**/*.js']). But some plugins had names that made them load before angular and jquery. A solution is to manually load them first.

    ['vendor/angular.js', 'vendor/jquery.js', 'vendor/**/*.js]
    

    Luckily angular and jquery handle being loaded twice well enough. Edit: Although it's not really the best practice to load such large libraries twice, causing your minified file unnecessary bloat. (thanks @Kano for pointing this out!)

    Another issue was client-js the order was important in a way that it required the main app file to be loaded last, after all its dependencies have been loaded. Solution to that was to exclude and then include:

    ['app/**/*.js', '!app/app.js', 'app/app.js']
    

    This prevents app.js from being loaded along with all the other files, and only then includes it at the end.

提交回复
热议问题