合并在一个文件中时,缩小的Javascript不起作用 [英] Minified Javascript doesn't work when combined in one file

查看:68
本文介绍了合并在一个文件中时,缩小的Javascript不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的3个JS库位于各自独立的文件中。它们被评论为每个单独文件中缩小的代码

I have 3 JS libraries that I use that are in their own separate files. They are commented with the code minified in each individual file

file 1: http://jsfiddle.net/NGMVa/

file 2: http://jsfiddle.net/AzEME/

file 3: http://jsfiddle.net/qVkhn/

现在单独他们在我的应用程序中工作正常,不要抛出任何错误。但是我想加载更少的文件,所以我将它们组合成一个文件,如下所示: http://jsfiddle.net/Gxswy/

Now individually they work fine in my app, don't throw any errors. But I wanted to load less files so I combined them into one file like this: http://jsfiddle.net/Gxswy/

但是,在Chrome中,它会在文件的最后一行引发错误:

However, in Chrome it throws an error on the last line of the file:

Uncaught TypeError: undefined is not a function 

然后它没有不再工作了。在我合并之前,我没有更改代码中的任何内容,我只是将前3个文件的内容复制并粘贴到新文件中,它不再起作用了。不明白为什么将它们合并到一个文件似乎打破了功能

and it then it doesn't work anymore. I didn't change anything in the code before I combined them, I just copy and pasted the content of the first 3 files into the new one, and it doesn't work anymore. Don't understand why combining them into one file seems to break functionality

希望有人知道这里发生了什么?

Was hoping someone would have an idea what's going here?

推荐答案

确保在每个文件的末尾添加分号或连接,然后缩小,minifier应该处理它。

Make sure to add the semicolons at the end of each file or concatenate and then minify and minifier should take care of that.

请尝试以下代码: https://gist.github.com/elclanrs/4728677

这篇关于合并在一个文件中时,缩小的Javascript不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆