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?

3 Answers 3

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)

Sign up to request clarification or add additional context in comments.

3 Comments

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

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.

3 Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.