4

My grunt script generated by yeoman concats and minifies js files through useminPrepare, concat, and uglifyjs.

This is working great, but there is one js script that I do not want it to minify. How do I specify that in the grunt file?

Hisham
  • 1,305
  • 2
  • 15
  • 25
  • See question http://stackoverflow.com/questions/18453974/how-to-ignore-files-grunt-uglify – Ace Jul 07 '14 at 23:32
  • @Ace yes I saw that question, and it does answer the question if I'm configuring uglify specifically, but in my case I'm using useminPrepare to create the uglify configuration so I just gotta figure out the useminPrepare way of modifying the uglify configuration. – Hisham Jul 08 '14 at 01:32
  • Also @Ace in my case I'm using concat to concatenate all the scripts in one file. So should I exclude that one js file from concatenation and keep it on its own? – Hisham Jul 08 '14 at 01:36
  • If there are no conflicts when it is uncompressed in the concat file. I would keep it there and avoid an extra http request – Ace Jul 08 '14 at 05:45

4 Answers4

3

What you can do it's to put the files you don't want to minify outside of the build script, for example:

<!-- build:js js/app.js -->
<script src="js/app.js"></script>
<script src="js/minifythis.js"></script>
<script src="js/models/minifythis.js"></script>
<!-- endbuild -->
<script src="js/do-not-minify-this.js"></script>
Mimo
  • 6,015
  • 6
  • 36
  • 46
  • you'll still need to manually copy any files you are not minimizing. See my subsequent post for an example. – vt5491 Dec 03 '15 at 06:21
  • If you are using Grunt you will need to edit your Grunt file if you are putting files in a different directory. In my situation, I created an Angular folder so I added {,*/}*.js to the copy properties. Hope this helps. – Coded Container Oct 20 '16 at 16:07
2

I spent days looking for a solution to a problem similar to yours, and then I found a different question that has a answer that may fit solve your problem, as it solved mine: https://stackoverflow.com/a/24819171/785985

The solution is to define custom blocks to be processed by Grunt. Then you can specify one block with ['concat'] and another with ['concat', 'uglifyjs'].

Community
  • 1
  • 1
Rodrigo Saling
  • 396
  • 4
  • 9
1

If you choose to exclude the files from the minification tag per the item from John Locke, don't forget to manually copy those files to the 'dist' dir. Normally, when you minify files the resultant minified library is copied to the dist dir. But since you're not minifying them, you have to copy them yourself.

For example, I didn't want to compress the user scripts in my app to make it easier for people to examine the code online. After editing my 'index.html' to remove them from the tag:

'<!-- build:js({.tmp,app}) scripts/scripts.js -->'

I had to add the following to the copy step of my Gruntfile:

copy: {
  dist: {
    files: [
    ...
      {  // manually copy all the files you are not minimizing:
        expand: true,
        cwd: '<%= yeoman.app %>/scripts/',
        src:"{,*/}*.js",
        dest:"<%= yeoman.dist %>/scripts/"
      }
    ]
  },
  ...
},

The syntax for copying files is very prickly in Grunt. It took me a couple of tries to get it right.

vt5491
  • 2,254
  • 2
  • 22
  • 34
1

Just need to set a minimize option of that script to false in Gruntfile.js.

optimization: {
    minimize: false
}
oleedd
  • 388
  • 2
  • 15