3

I have a couple js files that I can seem to get GruntJs to concat/minify properly.

If I do each individually they work fine.

If I combine separately then attempt to minify just the combined file it doesn't work either.

Here is the error:
enter image description here

Any ideas on how to fix this? Or maybe what is causing it?

Community
  • 1
  • 1
Mike Fielden
  • 10,055
  • 14
  • 59
  • 99

3 Answers3

4

There is currently a problem with GruntJs and the BOM I mentioned in the comment of Derick's answer.

You can find the issue here: https://github.com/cowboy/grunt/issues/218#issuecomment-6329807

In Visual Studio to manually remove the BOM

Open the file > File > Advanced Save Options > Set the encoding to "Unicode without signature" > "Ok" That should remove it.

Mike Fielden
  • 10,055
  • 14
  • 59
  • 99
  • Great catch. I banged my head against the wall for an hour before I found your solution. VS 2012: Still inserting BOM by default with no way to configure the setting (as far as I can tell, anyway). – Christopher Jul 15 '12 at 01:48
  • @Christopher I updated my answer on how to remove the BOM within VS. It sucks but you only need to do it once for each of your files. – Mike Fielden Jul 16 '12 at 17:57
  • 1
    I do this already, but VS does not consistently persist this change. Further, it's on a per-file basis. Throw a small team, 200 JS modules and DSC on top--you have VS constantly re-inserting BOM, commit after commit. Even with periodic, project level BOM purges, VS continues to inject BOM on tracked, existing files. Anyway, kudos again to your insight. – Christopher Jul 17 '12 at 03:58
3

To clarify and make sure I understand:

  • You have 2 separate files. We'll call them File1 and File2
  • If you minify File1 by itself, it works fine
  • If you minify File2 by itself, it works fine
  • If you concat File1 and File2 together, then minify, you get this error

Is that correct?

If so, you probably have a missing semi-colon somewhere and are running in to errors caused by ASI (automatic semi-colon insertion).

(note that this is a guess based on the limited info you've provided. You would need to post a lot more detail about the files, the code, etc, to really give a better answer)

Derick Bailey
  • 72,004
  • 22
  • 206
  • 219
  • Your assumptions are correct. :) The files are a simple Backbone model and a jq plugin I wrote. I'll look for missing `;`... Thanks for the response – Mike Fielden Jun 08 '12 at 15:29
  • I lint'd the files and they all now have zero errors and it still doesnt work. If I `--force` it the file it produces just has the word `undefined`. – Mike Fielden Jun 08 '12 at 18:06
  • I figured out the problem. It was with files created within Visual Studio. It gives them a BOM that it was choking on. Remove that BOM and you're good to go – Mike Fielden Jun 08 '12 at 19:39
0

During concatenation of File1 and File2 u need add a seperator : ';' in your options

For example ,

concat : {
             options : {
                  seperator  :';'
             },
             dist : {
                 src : [ 'path/to/src/*.js'],
                 dest :  'path/to/dest.js'
             }
   } 
Bachan-user3143666
  • 343
  • 2
  • 5
  • 14