javascript – 在优化的脚本中嵌入require.js

前端之家收集整理的这篇文章主要介绍了javascript – 在优化的脚本中嵌入require.js前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
RequireJS有一个很好的功能,可以将JS项目优化为一个单独的脚本(让我们称之为foo.js).

如果我包含foo.js,我会得到:未捕获的ReferenceError:未定义define.如果我在foo.js之前添加require.js,那么错误就会消失,因为define是由RequireJS定义的.我不希望我的图书馆用户必须这样做才能使用它.

我可以让RequireJS以适当的方式嵌入foo.js中吗?连接文件是否可以接受?

解决方法

是的,RequireJS的维护者为此推出了一个项目,almond.

我没有用它,但从描述中:

“Some developers like to use the AMD API to code modular JavaScript,but after doing an optimized build,they do not want to include a full AMD loader like RequireJS,since they do not need all that functionality. […] By including almond in the built file,there is no need for RequireJS. “

原文链接:https://www.f2er.com/js/157493.html

猜你在找的JavaScript相关文章