将节点模块添加到ember CLI应用程序 [英] Add node module to ember CLI app

查看:101
本文介绍了将节点模块添加到ember CLI应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用这个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

I tried it by adding this to the Brocfile.js

app.import('node_modules/remarkable-regexp/index.js');

但它失败如下:


路径或模式node_modules / outstanding-regexp / index.js没有
匹配任何文件

Path or pattern "node_modules/remarkable-regexp/index.js" did not match any files


推荐答案

由于 outstanding-regexp 是一个npm模块,我相信将其与ember-cli集成的最佳方法是使用 ember-browserify

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应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆