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

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

    This was @1469's answer but he didn't make it clear why this works. Use concat to put all js files into one, this module does this in the order of file names, so I put a prefix to the file names based on orders. I believe it even has other options for ordering.

    concat: {
    
            js: {
                options: {
                    block: true,
                    line: true,
                    stripBanners: true
                },
                files: {
                    'library/dist/js/scripts.js' : 'library/js/*.js',
                }
            }
        },
    

    Then use uglify to create the minified ugly version:

    uglify: {
          dist: {
            files: {
              'library/dist/js/scripts.min.js': [
                'library/js/scripts.js'
              ]
    
            },
            options: {
    
            }
          }
        },
    

提交回复
热议问题