C:\Users\Administrator\Desktop\meteorApp> mkdir packages
現(xiàn)在我們可以在上面創(chuàng)建的文件夾中創(chuàng)建你的包。運行命令提示符運行以下命令。Username 是您的 Meteor 開發(fā)者的用戶名和package-name是你的包的名稱。
C:\Users\Administrator\Desktop\meteorApp\packages>meteor create --package username:package-name
為了能夠本地包添加到我們的應用程序,需要設置環(huán)境變量(ENVIRONMENT VARIABLE),將告訴 meteor 從本地文件夾加載包。右鍵單擊"計算機"圖標,然后選擇屬性/高級系統(tǒng)設置/環(huán)境變量/新建。
變量名應該是PACKAGE_DIR變量值路徑應該是指向創(chuàng)建的文件夾。在我們的示例中是:C:\Users\Administrator\Desktop\meteorApp\packages.
C:\Users\Administrator\Desktop\meteorApp>meteor add username:package-name
C:\Users\Adminitrator\Desktop\meteorApp>meteor add tinytest
如果你打開 package-name-test.js, 你會看到默認的測試例子。我們將用這個例子來測試應用程序。開發(fā) Meteor 包時,你應該要寫寫自己的測試。
C:\Users\Administrator\Desktop>meteor test-packages packages/package-name

我們可以在這個文件中編寫代碼?,F(xiàn)在我們在包中實現(xiàn)一些簡單的功能。包將日志記錄一些文本到控制臺。
myPackageFunction = function() {
console.log('This is simple package...');
}
這是我們可以設定一些程序包配置文件。 我們一會再回到它,但現(xiàn)在需要導出myPackageFunction,就可以在應用程序中使用它了。我們需要添加這些到 Package.onUse 函數(shù)內。該文件將是這個樣子。
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');
});
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"
});