【问题标题】:Specifying file path in grunt在 grunt 中指定文件路径
【发布时间】:2017-11-01 06:47:10
【问题描述】:

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

    //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”,它会缩小所有文件,所以我以数组格式给出文件路径。有什么方法可以轻松搞定?

【问题讨论】:

    标签: npm gruntjs grunt-contrib-uglify


    【解决方案1】:

    可以用这些文件声明一个变量,并将该变量作为值传递给 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']);
        }
    

    【讨论】:

      猜你喜欢
      • 2014-10-25
      • 2016-12-12
      • 2015-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多