无法将JavaScript库加载到Meteor应用程序中 [英] Unable to load javascript library into Meteor app

查看:69
本文介绍了无法将JavaScript库加载到Meteor应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用带有Meteor应用程序的fabric.js库时遇到了麻烦,遗憾的是我无法完全将其添加到我的应用程序中,更不用说调用它了。最简单的娱乐活动如下:

I'm having trouble using the fabric.js library with a Meteor app, and unfortunately I can't quite get past the stage of adding it to my app, much less invoking it. The easiest recreation is as follows:

> mrt create test
> cd test
> mkdir client
> curl -o ./client/all.js http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.2.0/fabric.all.min.js
> mrt

转到localhost:3000显示以下控制台输出:

Going to localhost:3000 shows the following console output:

Uncaught TypeError: Cannot read property 'object' of undefined    all.js:4074
global.fabric.global.fabric                                       all.js:4074
(anonymous function)                                              all.js:4936
(anonymous function)

第4074行of all.js是第二行:

And line 4074 of all.js is the second line here:

var fabric = global.fabric || (global.fabric = { }),
    extend = fabric.util.object.extend,
    capitalize = fabric.util.string.capitalize,
    clone = fabric.util.object.clone,
    toFixed = fabric.util.toFixed,
    multiplyTransformMatrices = fabric.util.multiplyTransformMatrices;

我很确定我做错了什么(与织物或布料的问题相反)流星)但我不知道在哪里。我也尝试将all.js文件放入我的公共目录中,虽然它没有抛出相同的TypeError,但它确实使得结构变量似乎在我的任何地方都不可用代码。

I'm pretty certain I'm doing something wrong (as opposed to the problem being with fabric or meteor) but I'm not sure where. I've also tried placing the all.js file into my public directory and, while that doesn't throw the same TypeError, it does make it so that the fabric variable seems to be unavailable anywhere in my code.

将fabric.js正确加载到我的应用程序中的任何帮助都会很棒。

Any help with properly loading fabric.js into my app would be great.

推荐答案

请您尝试将库文件放入client / compatibility子目录中。在Meteor中导入的任何javascript文件都包含在闭包中,您无法轻松访问全局范围。客户端/兼容性是不会对库应用闭包的地方。

Would you please try to put the library file into the client/compatibility subdirectory. Any javascript files imported in Meteor is wrapped in closure in which you cannot easily access the global scope. client/compatibility is the place that no closure would be applied to the library.

http://docs.meteor.com/#structuringyourapp 你可以在这里找到更多关于导入库问题的讨论。

http://docs.meteor.com/#structuringyourapp you can find more talking about the importing library issue here.

这篇关于无法将JavaScript库加载到Meteor应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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