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
The browserify noise is probably the preferred method, but I hacked around it by creating a symlink in the vendor folder like so:
then
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:
ember-browserify
is a great choice for use in apps, and there is work being done to try to allow Ember CLI to import NPM packages without any extra help at all.However, if you're trying to make this work in both addons and apps you can take a slightly different approach, which is to manually modify the broccoli build chain to include your Node package.
This is a quick example of how this can be done in an addon's
index.js
file:A similar technique can be used for standard apps. Again, this method will be replaced soon as the Ember CLI team adds support for Node modules, so try to use it sparingly and keep up to date with Ember CLI!
Update you ember-cli to
v2.15.0-beta.1
. The new version allows you to useapp.import
withnode_modules
For more information check https://github.com/ember-cli/ember-cli/pull/7045
As of Ember-CLI 2.15.0, you can now import node modules directly. To demonstrate, ensure your app is on Ember-CLI 2.15.0, then try installing Moment.js:
yarn add moment
app.import('node_modules/moment/moment.js')
to yourember-cli-build.js
file.window
object:window.moment
.import moment from 'moment'
, you can generate a vendor shim. See this link for details.This won't work for node modules that don't provide a single JavaScript bundle (you will need to bundle using the methods described in other comments), but it's already a huge improvement.