在grunt中指定文件路径

时间:2017-11-01 06:47:11

标签: npm gruntjs grunt-contrib-uglify

我正在使用grunt进行缩小,使用npm来管理插件。我在下面给出了我的咕噜声配置。

    //Grunt configuration
    module.exports = function(grunt) {

      grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),


        uglify: {


          core_modules: {
            options: {
              beautify: false
            },
            files: {
              'resources/dist/core.min.js': [   "node_modules/jquery/dist/jquery.js",
                                                "node_modules/angular/angular.js",
                                                "node_modules/popper.js/dist/umd/popper.js",
                                                "node_modules/bootstrap/dist/js/bootstrap.js",
                                                "node_modules/jquery-ui-dist/jquery-ui.js",
                                                "node_modules/angular-animate/angular-animate.js",
                                                "node_modules/angular-material/angular-material.js",
                                                "node_modules/angular-aria/angular-aria.js",
                                                "node_modules/angular-sanitize/angular-sanitize.js",
                                                "node_modules/angular-ui-bootstrap/dist/ui-bootstrap.js",
                                                "node_modules/@uirouter/angularjs/release/angular-ui-router.js"
],
            },
          },


        },

      });

      //Grunt Plugins
      grunt.loadNpmTasks('grunt-contrib-uglify');


      //Default Tasks
      grunt.registerTask('default', ['uglify']);
    }

如果我给“node_modules / ** / * .js”它正在缩小所有文件,所以我给出了数组格式的文件路径。有什么方法可以轻松完成吗?

1 个答案:

答案 0 :(得分:0)

可以使用这些文件声明变量,并将变量作为值提供给dest,

var files= [   "node_modules/jquery/dist/jquery.js",
                                                "node_modules/angular/angular.js",
                                                "node_modules/popper.js/dist/umd/popper.js",
                                                "node_modules/bootstrap/dist/js/bootstrap.js",
                                                "node_modules/jquery-ui-dist/jquery-ui.js",
                                                "node_modules/angular-animate/angular-animate.js",
                                                "node_modules/angular-material/angular-material.js",
                                                "node_modules/angular-aria/angular-aria.js",
                                                "node_modules/angular-sanitize/angular-sanitize.js",
                                                "node_modules/angular-ui-bootstrap/dist/ui-bootstrap.js",
                                                "node_modules/@uirouter/angularjs/release/angular-ui-router.js"
];
 //Grunt configuration
    module.exports = function(grunt) {

      grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),


        uglify: {


          core_modules: {
            options: {
              beautify: false
            },
            files: {
              'resources/dist/core.min.js': files,
            },
          },


        },

      });

      //Grunt Plugins
      grunt.loadNpmTasks('grunt-contrib-uglify');


      //Default Tasks
      grunt.registerTask('default', ['uglify']);
    }
相关问题