Writing npm Packages
Writing npm Packages
To create a new npm package:
mkdir my-package cd my-package/ meteor npm init
The last command creates a package.json
file and prompts you for the package information. You may skip everything but name
, version
, and entry point
. You can use the default index.js
for entry point
. This file is where you set your package’s exports:
// my-package/index.js exports.myPackageLog = function() { console.log("logged from my-package"); };
Now apps that include this package can do:
import { myPackageLog } from 'my-package' myPackageLog(); // > "logged from my-package"
When choosing a name for your npm package, be sure to follow the 登录查看完整内容