禁用Grunt中的缩小

禁用Grunt中的缩小

本文介绍了禁用Grunt中的缩小(Yeoman)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近通过Yeoman开始使用GruntJS,我喜欢Javascript缩小的想法,但是它在开发过程中遇到困难。我试图在Gruntfile的不同组合中禁用uglify,usemin等,但一切似乎都依赖于另一件事情,并打破了过程。有没有简单的方法来禁用缩小?我使用了Yeoman提供的最新版Grunt,我发现旧版解决方案与使用Yeoman的usd不同,Gruntfile设置不同。

I recently started using GruntJS through Yeoman and I like the idea of Javascript minification, but it presents difficulties during development. I tried to disable uglify,usemin, etc in different combinations in the Gruntfile but everything seems to be dependent on another thing and breaks the process. Is there a simple way to disable minification? I am using the latest versionof Grunt offered by Yeoman to date, I found that older solutions have a different Gruntfile setup than that usd with Yeoman.

这是我的Gruntfile:

Here is my Gruntfile:

// Reads HTML for usemin blocks to enable smart builds that automatically
// concat, minify and revision files. Creates configurations in memory so
// additional tasks can operate on them
useminPrepare: {
  options: {
    dest: '<%= config.dist %>'
  },
  html: '<%= config.app %>/index.html'
},

推荐答案

此注释块位于您的Gruntfile中:

This comment block was in your Gruntfile:

// By default, your `index.html`'s <!-- Usemin block --> will take care
// of minification. These next options are pre-configured if you do not
// wish to use the Usemin blocks.

基于此,移除<! - Usemin块 - > from your index.html file should prevent the useminPrepare grunt task to reduce your javascript。

Based on this, removing the <!-- Usemin block --> from your index.html file should prevent the useminPrepare grunt task from minifying your javascript.

此外,您可以编辑您的 uglify 任务,以创建新文件,以便不会通过添加 .min 到文件扩展名:

Additionally, you can edit your uglify task to create new files to not overwrite your dev files by adding .min to the file extension:

 uglify: {
   dist: {
     files: {
       '<%= config.dist %>/scripts/scripts.js': [
         '<%= config.dist %>/scripts/scripts.min.js'
       ]
     }
   }
 },

这篇关于禁用Grunt中的缩小(Yeoman)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 19:42