将节点模块添加到 ember CLI 应用程序 [英] Add node module to ember CLI app
问题描述
我想使用这个 Node.js 模块 https://www.npmjs.com/package/remarkable-regexp 在我的 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
app.import('node_modules/remarkable-regexp/index.js');
但它失败了:
路径或模式node_modules/remarkable-regexp/index.js"没有匹配任何文件
Path or pattern "node_modules/remarkable-regexp/index.js" did not match any files
推荐答案
由于 remarkable-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 import 导入模块,方法是在其前面加上 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 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!