Spinejs 依赖加载顺序

发布于 2025-01-03 07:34:49 字数 583 浏览 2 评论 0原文

我正在尝试在 Spine.js 应用程序中使用 elycharts 。 Elycharts 猴子补丁 jQuery 添加 $('...').chart(...)。不幸的是,我收到一条错误消息,指出 $ 没有函数“chart”。

由于这是我的第一个 Spine.js 应用程序,因此我使用 spin.app 生成了它。它使用 jQuery 作为 NPM 模块。 Elycharts 对 CommonJS 不友好,因此必须包含在 slug.json 的“libs”部分中。根据 Spine 文档(请参阅 Hem 文档 中的 slug.json),“libs”中的任何文件都会在“依赖项”中的任何内容之前加载。所以我很确定问题是 elycharts 在 jQuery 之前加载,试图做它的猴子补丁,但由于 $ 尚未定义,它会默默地失败。

有没有人看到过与此类似的问题,使用依赖于已通过 NPM 包含的库的“库”?有没有办法在 libs 之外更精细地控制 spin.js 中的加载顺序 ->依赖关系?

I'm trying to use elycharts in a Spine.js app. Elycharts monkey-patches jQuery to add $('...').chart(...). Unfortunately, I'm just getting an error saying $ doesn't have function "chart".

As this is my first Spine.js app I generated it using spine.app. This uses jQuery as an NPM module. Elycharts is not CommonJS friendly and therefore must be included in the "libs" section of slug.json. According to the Spine docs (see slug.json in the Hem documentation), any files in "libs" get loaded before anything in "dependencies". So I'm pretty sure the problem is elycharts is loading before jQuery, trying to do its monkey-patch, but since $ isn't defined yet it fails silently.

Has anyone seen issues similar to this, using "libs" that depend on libraries already included via NPM? Is there a way to more finely control the load order in spine.js beyond libs -> dependencies?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生死何惧 2025-01-10 07:34:49

对我来说“不太好”的解决方案是这样的:

<script type="text/javascript">
    var jQuery  = require("jqueryify");
    var exports = this;
    jQuery(function(jQuery){
// load jquery dependant libraries                  
    $.getScript("//cdnjs.cloudflare.com/ajax/libs/waypoints/1.1.6/waypoints.min.js", function() {
        var App = require("index");
        exports.app = new App({el: $("#wrapper")});      
    });
</script>

所以技巧是在应用程序初始化之前加载 jquery 依赖库。
希望它能帮助某人。

For me the "not so nice" solution was this:

<script type="text/javascript">
    var jQuery  = require("jqueryify");
    var exports = this;
    jQuery(function(jQuery){
// load jquery dependant libraries                  
    $.getScript("//cdnjs.cloudflare.com/ajax/libs/waypoints/1.1.6/waypoints.min.js", function() {
        var App = require("index");
        exports.app = new App({el: $("#wrapper")});      
    });
</script>

So the trick is to load the jquery dependant libraries before the app is initialized.
Hope it helps someone.

顾冷 2025-01-10 07:34:49

我一直在寻找一种解决方案,将 Twitter Bootstrap (也依赖于 jQuery)包含到 spin.js 应用程序(使用 spin 脚本生成)中。我发现的最好的方法是:只需将 jqueryify 替换为 jquery.js

删除这些行:

./app/lib/setup.coffee:3:require('jqueryify')
./package.json:9:    "jqueryify": "~0.0.1",
./public/index.html:9:    var jQuery  = require("jqueryify");
./slug.json:5:    "jqueryify", 

然后将 jquery.js 和您的 javascript 库放入 app/lib 中,并将它们添加到 slug.json libs 数组中:

"libs": [
  "app/lib/jquery.js",
  "app/lib/jquery-dependent-3rd-party-lib.js"
]

瞧!

PS 至于 Twitter Bootstrap,我建议将整个 bootstrap 目录放入 public 目录中(因为它也附带 CSS 和图像)并从 slug.json< 引用它/code> 相应地:

"libs": [
  "app/lib/jquery.js",
  "public/bootstrap/js/bootstrap.min.js"
]

这样更新 Twitter Bootstrap 库将变得微不足道 — 无需将文件分散到各处。

I've been looking for a solution to include Twitter Bootstrap (also depends on jQuery) into spine.js application (generated with spine script). The best I've found is this: simply replace jqueryify with jquery.js!

Drop these lines:

./app/lib/setup.coffee:3:require('jqueryify')
./package.json:9:    "jqueryify": "~0.0.1",
./public/index.html:9:    var jQuery  = require("jqueryify");
./slug.json:5:    "jqueryify", 

Then put jquery.js and your javascript library into app/lib and add them to slug.json libs array:

"libs": [
  "app/lib/jquery.js",
  "app/lib/jquery-dependent-3rd-party-lib.js"
]

And voilà!

P.S. as for Twitter Bootstrap, I recommend putting whole bootstrap directory into public directory (because it's also shipped with CSS and images) and reference it from slug.json accordingly:

"libs": [
  "app/lib/jquery.js",
  "public/bootstrap/js/bootstrap.min.js"
]

That way updating Twitter Bootstrap library will be trivial — no need to scatter files all over the place.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文