Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

javascript - Add node module to ember CLI app

I would like to use this Node.js module https://www.npmjs.com/package/remarkable-regexp in my Ember-CLI application.

How do I make it available to the Ember application?

I tried it by adding this to the Brocfile.js

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

but it fails like this:

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Since remarkable-regexp is a npm module, I believe the best way to integrate it with ember-cli is by using ember-browserify.

Within your ember-cli app you can install the addon by running npm install --save-dev ember-browserify

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...