Meteor 包,如何添加静态文件 [英] Meteor package, how to add static files

查看:20
本文介绍了Meteor 包,如何添加静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个包,对于客户端,我需要添加一些静态文件,如字体和图像.在尝试了一些过时 解决方案后,我发现似乎没有什么对我有用.我应该如何添加这些文件?在我的包中创建一个公共文件夹?使用 api.addFiles 添加文件?这甚至可能吗?

I'm creating a package and, for the client side, I need to add some static files like fonts and images. After trying some outdated solution I found nothing seemed to work for me. How should I add those files? Create a public folder inside my package? Adding the files with api.addFiles? Is this even possible?

推荐答案

更新:meteor 1.2

您现在应该使用 api.addAssets 将静态文件添加到您的包中.

update: meteor 1.2

You should now use api.addAssets to add static files to your package.

您可以将静态资产添加到任何包中,它们将由meteor 提供服务.证明这一点的最简单方法是使用示例.查看 hopscotch 的来源.

You can add static assets to any package and they will be served by meteor. The easiest way to demonstrate this is with an example. Have a look at the source for hopscotch.

该包包含一个 img 目录,其中包含文件 sprite-green-0.3.png.如果您查看 package.js 文件,您可以看到它通过以下方式添加到客户端:

The package contains an img directory with the file sprite-green-0.3.png. If you look at the package.js file you can see that it gets added to the client with:

api.addFiles('img/sprite-green-0.3.png', 'client');

将包添加到您的项目后,您可以直接使用此 URL 访问该文件:

After adding the package to your project, you can access the file directly with this URL:

http://localhost:3000/packages/hopscotch/img/sprite-green-0.3.png

总而言之,您可以使用 api.addFiles 添加静态资产.所有资产都可以在像 /packages/[package name]/[path to asset] 这样的路径下访问.

In summary, you can use api.addFiles to add static assets. All assets will be accessable under a path like /packages/[package name]/[path to asset].

请注意,对于不应自动加载的资产,您可以将 {isAsset: true} 作为第三个参数添加到 addFiles.这篇文章 包含一个使用示例.

Note that you can add {isAsset: true} as a third argument to addFiles for assets which should not be automatically loaded. This post contains an example of its use.

这篇关于Meteor 包,如何添加静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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