简体   繁体   English

在Grunt(Yeoman)中禁用缩小

[英]Disable minification in Grunt (Yeoman)

I recently started using GruntJS through Yeoman and I like the idea of Javascript minification, but it presents difficulties during development. 我最近开始通过Yeoman使用GruntJS,我喜欢Javascript缩小的想法,但它在开发过程中遇到了困难。 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. 我试图在Gruntfile中以不同的组合禁用uglify,usemin等,但是一切似乎都依赖于另一件事并打破了这个过程。 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. 我正在使用Yeoman提供的最新版本的Grunt,我发现旧的解决方案具有与使用Yeoman的usd不同的Gruntfile设置。

Here is my Gruntfile: 这是我的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'
},

http://hastebin.com/gicabukojo.js http://hastebin.com/gicabukojo.js

I needed to tweak the usemin flow: option: 我需要调整usemin flow:选项:

as per yeoman grunt usemin's fine manual , the default flow: is 根据yeoman grunt usemin的精细手册 ,默认flow:

{ steps: { js: ['concat', 'uglify'], css: ['concat', 'cssmin'] }, post: {} }

Here is a gist of how I modified my yo webapp Gruntfile.js to remove uglify from the flow. 这里是我如何修改要点我哟web应用Gruntfile.js删除uglify从流。

This comment block was in your Gruntfile: 这个评论块在你的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.

Based on this, removing the <!-- Usemin block --> from your index.html file should prevent the useminPrepare grunt task from minifying your javascript. 基于此,从index.html文件中删除<!-- Usemin block -->应该可以防止useminPrepare grunt任务缩小你的javascript。

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任务以创建新文件,以通过将.min添加到文件扩展名来覆盖您的dev文件:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM