问题描述
我想使用这个Node.js模块在我的Ember-CLI应用程序中。
I would like to use this Node.js module https://www.npmjs.com/package/remarkable-regexp in my Ember-CLI application.
如何使它可用于Ember应用程序?
How do I make it available to the Ember application?
我尝试通过将它添加到 Brocfile.js
I tried it by adding this to the Brocfile.js
app.import('node_modules/remarkable-regexp/index.js');
但它失败如下:
推荐答案
由于 outstanding-regexp
是一个npm模块,我相信将其与ember-cli集成的最佳方法是使用。
Since remarkable-regexp
is a npm module, I believe the best way to integrate it with ember-cli is by using ember-browserify.
内您的ember-cli应用程序可以通过运行 npm install来安装插件--save-dev ember-browserify
Within your ember-cli app you can install the addon by running npm install --save-dev ember-browserify
因此,您可以使用ES6导入导入模块,前缀为 npm:
So, you can import the modules using ES6 import by prefixing it with npm:
import Remarkable from 'npm:remarkable';
import Plugin from 'npm:remarkable-regexp';
var plugin = Plugin(
// regexp to match
/@(\w+)/,
// this function will be called when something matches
function(match, utils) {
var url = 'http://example.org/u/' + match[1]
return '<a href="' + utils.escape(url) + '">'
+ utils.escape(match[1])
+ '</a>'
}
)
new Remarkable()
.use(plugin)
.render("hello @user")
// prints out:
// <p>hello <a href="http://example.org/u/user">user</a></p>
这篇关于将节点模块添加到ember CLI应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!