本文介绍了如何使用goog.provide和goog.require加载我自己的js模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我们正在尝试将我们的项目的包装从dojo切换到谷歌关闭,但到目前为止我们还没有运气。这是一个简单的例子,说明了我们正在努力完成的工作:We are trying to switch the packaging for our project from dojo to google closure, but we haven't had any luck so far. Here is a simple example that illustrates what we are trying to accomplish: c> -d字符串- where the first string it the path to my JS file relative to closure-library/closure/goog/base.js (this is important!), the second array is the list of goog.provide-d strings, and the last array is the list of goog.require-d strings.现在在app.html我有:Now in app.html I have:<script src="closure-library/closure/goog/base.js"></script><script src="my-deps.js"></script><script> goog.require("proj.ui");</script><script> // here we can use the required objects</script>注意: 除了包含封闭的base.js之外,我还包括我生成的deps.js 正如教程 goog.require 调用必须在一个单独的脚本标签中,因为它附加一个脚本标签来加载所需的脚本,并在当前脚本标记完成处理之后加载脚本标签。 In addition to including closure's base.js, I include my generated deps.jsAs mentioned in the tutorial the goog.require call has to be in a separate script tag, because it appends a script tag to load the required scripts and they are loaded after the current script tag finished processing. Gotchas: 上面讨论的路径与base.js.相关的问题。 goog.require 通过连接base.js基本URL(即没有base.js leafname)和第一个参数来创建脚本URL来加载deps.js中的goog.addDependency 。 calcdeps.py在Windows上不能正常工作,特别是在deps.js字符串文字中使用反斜杠 如果某些内容不正常,可能需要查看所有问题提及calcdeps ,并确保您有最新的结帐。 The described above issue with paths being relative to base.js. goog.require creates the script URL to load by concatenating the base.js base URL (i.e. without base.js leafname) and the first parameter to goog.addDependency in deps.js.calcdeps.py doesn't work well on Windows, in particular using the backslashes in the deps.js string literalsIf something doesn't work well, you may want to look through all issues mentioning calcdeps and make sure you have an up to date checkout. 这篇关于如何使用goog.provide和goog.require加载我自己的js模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 09:18