简体   繁体   English

将本地JS文件导入流星

[英]Import local JS files into Meteor

I'm having terrible problems when trying to import an external JS project into my meteor folder. 尝试将外部JS项目导入流星文件夹时遇到严重问题。 This is the project I'll like to use: http://www.outsharked.com/imagemapster/default.aspx?demos.html#beatles 这是我要使用的项目: http : //www.outsharked.com/imagemapster/default.aspx?demos.html#beatles

As you can see, it is necessary to import two scripts. 如您所见,有必要导入两个脚本。 The first one is JQuery, and that was easily solved by adding it with meteor add jquery . 第一个是JQuery,可以很容易地通过与meteor add jquery添加它来解决。

The problem came out when I tried to import the second script. 当我尝试导入第二个脚本时出现了问题。 I'm not sure how I can use it because, as far as I know, on meteor you cannot just import your script into the head section. 我不确定如何使用它,因为据我所知,在流星上您不能仅将脚本导入到头部。 For that reason, I've created a new template that is rendered and I put the code in there, but nothing happenend. 因此,我创建了一个新的模板,并将其放入其中,但是没有任何反应。 Later on I've created an event that calls the JS when the image is clicked but without any success. 稍后,我创建了一个事件,该事件在单击图像时成功调用JS。

My question is, Which is the correct way to import a local JS code in meteor as in HTML is done with: 我的问题是,在流星中导入本地JS代码的正确方法是正确的,就像在HTML中那样:

<script type="text/javascript" src="../dist/jquery.imagemapster.js"></script>

Since jquery-imagemapster is available as an npm package you can do: 由于jquery-imagemapster可作为npm软件包提供,因此您可以执行以下操作:

$ npm install jquery-imagemapster

In your project directory and make it available to your project that way. 在您的项目目录中,以这种方式使其可用于您的项目。

In early versions of Meteor packages were only available via atmosphere and $ meteor add . 在早期版本的Meteor软件包只能通过大气层和$ meteor add Later they added npm support and all npm packages became available. 后来他们添加了npm支持,所有npm软件包都可用。

Prefix npm installs with “meteor” -> “meteor npm install —save 'js file'. 前缀npm安装时使用“流星”->“流星npm安装-保存'js文件'。 Initializing will be the same as it would be in any other front end environment as will importing it. 初始化将与在其他任何前端环境中进行的导入相同。 If you're having trouble after that, check for it's existance in your browser console and work from there using its built in properties and methods. 如果之后遇到问题,请检查浏览器控制台中是否存在该问题,然后使用其内置的属性和方法从那里进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM