Example: npm
Framer modules work with npm, a package manager where thousands of JavaScript packages are published. Let’s import the Moment.js library. Make sure you already have npm installed.
译:Framer模块,NPM,数以千计的JavaScript包发布的软件包管理器工作。让我们导入Moment.js库。请确保你已经安装了NPM。
# In your terminal
cd ~/my-project.framer
npm install moment
Create a new module in /modules, and name it npm.coffee. Beware that if you name the file the same as the npm module (like moment.coffee), you could run into a recursive import problem.
译:在模块中创建一个新模块,并将其命名为npm.coffee。 注意,如果你的文件名称相同NPM模块(像moment.coffee),你可以运行到一个递归的导入问题。
# File: modules/npm.coffee
exports.moment = require "moment"
After a refresh, you can import moment into your project.
译:刷新后,您可以导入到您的项目中
# Import the moment module from your npm index
moment = require("npm").moment
# Or use this nice shortcut, which is the exact same
{moment} = require "npm"
And now you can use it in your project:
译:现在你可以在你的项目中使用它:
dayStarted = new Layer
html: moment().startOf("day").fromNow()