简体   繁体   中英

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. 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.

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'
},

http://hastebin.com/gicabukojo.js

I needed to tweak the usemin flow: option:

as per yeoman grunt usemin's fine manual , the default flow: is

{ 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.

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.

Based on this, removing the <!-- Usemin block --> from your index.html file should prevent the useminPrepare grunt task from minifying your 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: {
   dist: {
     files: {
       '<%= config.dist %>/scripts/scripts.js': [
         '<%= config.dist %>/scripts/scripts.min.js'
       ]
     }
   }
 },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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