Spinejs 依赖加载顺序
我正在尝试在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对我来说“不太好”的解决方案是这样的:
所以技巧是在应用程序初始化之前加载 jquery 依赖库。
希望它能帮助某人。
For me the "not so nice" solution was this:
So the trick is to load the jquery dependant libraries before the app is initialized.
Hope it helps someone.
我一直在寻找一种解决方案,将 Twitter Bootstrap (也依赖于 jQuery)包含到 spin.js 应用程序(使用 spin 脚本生成)中。我发现的最好的方法是:只需将
jqueryify
替换为jquery.js
!删除这些行:
然后将
jquery.js
和您的 javascript 库放入app/lib
中,并将它们添加到slug.json libs
数组中:瞧!
PS 至于 Twitter Bootstrap,我建议将整个
bootstrap
目录放入public
目录中(因为它也附带 CSS 和图像)并从slug.json< 引用它/code> 相应地:
这样更新 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
withjquery.js
!Drop these lines:
Then put
jquery.js
and your javascript library intoapp/lib
and add them toslug.json libs
array:And voilà!
P.S. as for Twitter Bootstrap, I recommend putting whole
bootstrap
directory intopublic
directory (because it's also shipped with CSS and images) and reference it fromslug.json
accordingly:That way updating Twitter Bootstrap library will be trivial — no need to scatter files all over the place.