Minifying scripts using GruntJs

懵懂的女人 提交于 2019-12-07 11:58:50

问题


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:

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


回答1:


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.




回答2:


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)




回答3:


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


来源:https://stackoverflow.com/questions/10951354/minifying-scripts-using-gruntjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!