Grunt-无法缩小js文件

Grunt - not able to minifiy js file

本文关键字:js 文件 缩小 Grunt-      更新时间:2023-09-26

我正在我的应用程序上运行gruntjshintingminification,其中jshint正在工作,但minification命令根本不工作。得到这样的错误:

D:'grunt>grunt min
Warning: Task "min" not found. Use --force to continue.
Aborted due to warnings.

这是我的配置文件:

module.exports = function(grunt){
    // Project configuration.
  grunt.initConfig({
    jshint: {
        options: {
            curly: true,
            eqeqeq: true,
            eqnull: true,
            browser: true,
            globals: {
              jQuery: true
            }
        },
      myFiles: ['js/**/*.js']
    },
    min:{
        dest : {
            src:'js/app.js',
            dest:'js/app.min.js'
        }
    },
  });
  // Each plugin must be loaded following this pattern
  grunt.loadNpmTasks('grunt-contrib-jshint');
}

在这个项目中,我安装的模块是:

grunt, grunt-contrib-jshint, jshint-我不知道我做错了什么。。请任何人帮我解决这个问题。

提前感谢!

要缩小您需要的文件,例如uglify。

使用以下命令安装:

npm install grunt-contrib-uglify --save-dev

然后,将其添加到Gruntfile 中

grunt.loadNpmTasks('grunt-contrib-uglify');

最后,您必须更改Gruntfile的代码:

  grunt.initConfig({
    jshint: {
      options: {
        curly: true,
        eqeqeq: true,
        eqnull: true,
        browser: true,
        globals: {
          jQuery: true
        }
      },
    myFiles: ['js/**/*.js']
  },
  uglify:{
    dest : {
        files: {
          'js/app.min.js': ['js/app.js']
        }
    }
  },
});

谨致问候。

您需要安装类似的迷你任务

grunt-contrib-uglify 

以便缩小文件。

更多关于Grunt contrib丑陋

使用uglify 的Grunt文件样本