Meteor package.js
C:\Users\Administrator\Desktop\meteorApp> mkdir packages
现在我们可以在上面创建的文件夹中创建你的包。运行命令提示符运行以下命令。Username 是您的 Meteor 开发者的用户名和package-name是你的包的名称。
C:\Users\Administrator\Desktop\meteorApp\packages>meteor create --package username:package-name
添加包
为了能够本地包添加到我们的应用程序,需要设置环境变量(ENVIRONMENT VARIABLE),将告诉 meteor 从本地文件夹加载包。右键单击"计算机"图标,然后选择属性/高级系统设置/环境变量/新建。
变量名应该是PACKAGE_DIR变量值路径应该是指向创建的文件夹。在我们的示例中是:C:\Users\Administrator\Desktop\meteorApp\packages.
C:\Users\Administrator\Desktop\meteorApp>meteor add username:package-name
包文件
- package-name-test.js
- package-name.js
- package.js
- README.md
测试包(package-name-test.js)
C:\Users\Adminitrator\Desktop\meteorApp>meteor add tinytest
如果你打开 package-name-test.js, 你会看到默认的测试例子。我们将用这个例子来测试应用程序。开发 Meteor 包时,你应该要写写自己的测试。
C:\Users\Administrator\Desktop>meteor test-packages packages/package-name


package.js文件
我们可以在这个文件中编写代码。现在我们在包中实现一些简单的功能。包将日志记录一些文本到控制台。
packages/package.js
myPackageFunction = function() {
console.log('This is simple package...');
}
package-name.js文件
这是我们可以设定一些程序包配置文件。 我们一会再回到它,但现在需要导出myPackageFunction,就可以在应用程序中使用它了。我们需要添加这些到 Package.onUse 函数内。该文件将是这个样子。
packages/package-name.js
Package.describe({
name: 'username:package-name',
version: '0.0.1',
// Brief, one-line summary of the package.
summary: '',
// URL to the Git repository containing the source code for this package.
git: '',
// By default, Meteor will default to using README.md for documentation.
// To avoid submitting documentation, set this field to null.
documentation: 'README.md'
});
Package.onUse(function(api) {
api.versionsFrom('1.2.1');
api.use('ecmascript');
api.addFiles('mypackage.js');
api.export('myPackageFunction'); // We are exporting the function we created above...
});
Package.onTest(function(api) {
api.use('ecmascript');
api.use('tinytest');
api.use('username:package-name');
api.addFiles('package-name-tests.js');
});
packages/package.js
if(Meteor.isClient) {
myPackageFunction();
}


这是一个例子文件...看看一就知道了
/* Information about this package */
Package.describe({
// Short two-sentence summary.
summary: "What this does",
// Version number.
version: "1.0.0",
// Optional. Default is package directory name.
name: "username:package-name",
// Optional github URL to your source repository.
git: "https://github.com/something/something.git",
}); /* This defines your actual package */
Package.onUse(function (api) {
// If no version is specified for an 'api.use' dependency, use the
// one defined in Meteor 0.9.0.
api.versionsFrom('0.9.0');
// Use Underscore package, but only on the server.
// Version not specified, so it will be as of Meteor 0.9.0.
api.use('underscore', 'server');
// Use iron:router package, version 1.0.0 or newer.
api.use('iron:router@1.0.0');
// Give users of this package access to the Templating package.
api.imply('templating')
// Export the object 'Email' to packages or apps that use this package.
api.export('Email', 'server');
// Specify the source code for the package.
api.addFiles('email.js', 'server');
}); /* This defines the tests for the package */
Package.onTest(function (api) {
// Sets up a dependency on this package
api.use('username:package-name');
// Allows you to use the 'tinytest' framework
api.use('tinytest@1.0.0');
// Specify the source code for the package tests
api.addFiles('email_tests.js', 'server');
}); /* This lets you use npm packages in your package*/
Npm.depends({
simplesmtp: "0.3.10",
"stream-buffers": "0.2.5"
});
Meteor package.js的更多相关文章
- 更改package.js后重新加载
node --save可有省略掉手动修改package.json的步骤 当你为你的模块安装一个依赖模块时,正常情况下你得先安装他们(在模块根目录下npm install module-name), ...
- 安装package.js
- windows下Meteor+AngularJS开发的坑
有复杂的地方我再开贴记录,这里只记录容易解决的坑. 1. windows下手工增加smart package.直接将下载下来的包扔到meteor package中.记得将文件夹名字改得和smart.j ...
- 示例开发过程记录:meteor,react,apollo
本示例记录一个开发过程: 1)参考 Meteor React TUTORIAL教程 https://www.meteor.com/tutorials/react/creating-an-app 2). ...
- vue.js源码精析
MVVM大比拼之vue.js源码精析 VUE 源码分析 简介 Vue 是 MVVM 框架中的新贵,如果我没记错的话作者应该毕业不久,现在在google.vue 如作者自己所说,在api设计上受到了很多 ...
- vulcanjs 简单package 编写
vulcanjs 功能是以包进行管理,包里面包含了运行依赖的组件以及对于路由的注册 参考项目 项目结构 ├── README.md ├── license.md ├── package-lock.js ...
- OHIFViewer meteor build 问题
D:\Viewers-master\OHIFViewer>meteor build --directory d:/h2zViewerC:\Users\h2z\AppData\Local\.met ...
- 基于webpack和vue.js搭建开发环境
前言 在对着产品高举中指怒发心中之愤后,真正能够解决问题的是自身上的改变,有句话说的好:你虽然改变不了全世界,但是你有机会改变你自己.秉承着“不听老人言,吃亏在眼前”的优良作风,我还是决定玩火自焚. ...
- 用Javascript(js)进行HTML转义工具(处理特殊字符显示)
转自:http://blog.csdn.net/hj7jay/article/details/51280405 众所周知页面上的字符内容通常都需要进行HTML转义才能正确显示,尤其对于Input,T ...
随机推荐
- droplang - 删除一种 PostgreSQL 过程语言
SYNOPSIS droplang [ connection-option...] langname [ dbname] droplang [ connection-option...] --list ...
- com组件简单应用
1.打开VS2010,新建ATL COM 项目,步骤:“文件” -->“新建” -->“项目”,选择“Visual C++” -->“ATL 项目” ,填写“名称” FirstCOM ...
- 502 bad gateway nginx
此方法可能仅对于我的问题有效 我在VMware虚拟机启动docker container nginx的,一开始启动nginx的contatiner,在浏览器是可以正常访问的,但次日重新访问时就报502 ...
- 手动编译openslide
1.下载openslide源代码, 2.转到openslide代码目录: ./configure 3.安装依赖库: sudo apt-get update sudo apt-get install l ...
- 如何在Python中显式释放内存?
根据Python官方文档,您可以强制垃圾收集器释放未引用的内存gc.collect().例: import gc gc.collect() 所属网站分类: python高级 > 综合&其 ...
- 【转】Unable to load native-hadoop library for your platform(已解决)
1.增加调试信息寻找问题 2.两种方式解决unable to load native-hadoop library for you platform 附:libc/glibc/glib简介 参考: 1 ...
- EmpireofCode文档翻译 https://empireofcode.com/game/
In Campaign mode, you can check your strategies on already defeated bases. You will not lose your tr ...
- POJ 1985 Cow Marathon (求树的直径)
Description After hearing about the epidemic of obesity in the USA, Farmer John wants his cows to ge ...
- Http中cookie的使用以及用CookieManager管理cookie
前段时间项目需要做个接口,接口需要先登录才能进行下一步操作,这里就需要把登录的信息携带下去,进行下一步操作.网上查了很多资料,有很多种方法.下面就介绍较常用 的. 第一种方式: 通过获取头信息的方式获 ...
- CSS3 pointer-events:none 让你摆脱事件的烦恼
以前没遇到这个属性,在一个偶然的博文下发现该属性真的好用,你是否遇到过写鼠标移入显示文本的效果时,鼠标在元素内的每一次移动都会造成要显示文本的闪烁或是突然的消失?只要在被控制的元素中加上这个属性完美解 ...