Where did the grunt min task go?

限于喜欢 提交于 2020-01-04 12:57:11

问题


I watched many tutorials on grunt where some min task was used. I couldn't find any plugins referring to similar task. I would guess that devs have updated it and renamed to uglify am i right? And another issue i had was the installation of grunt. Can it still be installed globally, or should i install grunt-cli globally and grunt locally in order to use it for my local projects??

This:

sudo npm install -g grunt

doesn't work for me, only:

sudo npm install -g grunt-cli

npm install grunt --save-dev

Is the first method deprecated?

Edit:

Here is the video i'm refering to: http://www.youtube.com/watch?v=q3Sqljpr-Vc


回答1:


There are many different min libraries including these by the core grunt team:

  • grunt-contrib-cssmin (grunt-contrib-mincss is the older version)
  • grunt-contrib-htmlmin
  • grunt-contrib-imagemin
  • grunt-contrib-uglify <== for js minification

It is likely the one you are referring to is the uglify plugin, but hard to tell without knowing which tutorial you were watching.

As to installing, the second form is correct for grunt 4.x as described in the documentation




回答2:


I saw the same tutorial and I couldn't found min task too. 'min' seems using uglify internally so you can use uglify directly.

decalre task in gruntfile.js

uglify: {
  dist: {
    src: foo.js,
    dest: foo.min.js
  }
}

load plugin

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

and run

$ grunt uglify


来源:https://stackoverflow.com/questions/18431597/where-did-the-grunt-min-task-go

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!