如何将npm模块导入Polymer 2.0元素?

我试图了解,如果我在聚合物的领域甚至有可能做。 我目前的例子涉及到试图导入一个叫做currency-formatter的npm模块到一个可以调用的Polymer 2.0元素中。

我遇到的问题是,尽pipe我可以导入requirejs来查找npm模块,但是我似乎无法运行该模块,但是没有给出以下错误:

require.js:168未捕获错误:模块名称“currency-formatter”尚未加载上下文:_。 使用require([])

以此代码为例:

<link rel="import" href="bower_components/polymer/polymer-element.html"> <script src="node_modules/requirejs/require.js"></script> <dom-module id="currency-display"> <template> <style> :host { display: inline-block; } </style> <input type="text" value={{currency::input}}></input> <p>Currency: - {{formatCurrency}}</p> </template> <script> class CurrencyDisplay extends Polymer.Element { static get is() { return 'currency-display'; } static get properties() { return { currency: { type: String, value: 0, }, formatCurrency: { type: String, notify: true, computed: '_getCurrency(currency)' }, type: { type: String, value: 'USD', } }; } _getCurrency (currency) { var currencyFormatter = require('currency-formatter'); var formattedCurrency = currencyFormatter.format(parseInt(currency), { code: type }); return formattedCurrency; } } window.customElements.define(CurrencyDisplay.is, CurrencyDisplay); </script> </dom-module> 

帮助我了解我做错了什么。