Add node module to ember CLI app

后端 未结 5 1794
孤独总比滥情好
孤独总比滥情好 2020-12-16 17:01

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 applicat

5条回答
  •  感动是毒
    2020-12-16 17:28

    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 ''
          + utils.escape(match[1])
          + ''
      }
    )
    
    new Remarkable()
      .use(plugin)
      .render("hello @user")
    
    // prints out:
    // 

    hello user

提交回复
热议问题