Meteor package, how to add static files

别来无恙 提交于 2019-11-30 03:24:58

update: meteor 1.2

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


original answer

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.

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');

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

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].

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.

medhamza7

For assets file like favicon.ico or fonts files you can create a public folder.

You can check this answer or the documentation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!