UNPKG

2.73 kBMarkdownView Raw
1# ember-rollup [![npm version](https://badge.fury.io/js/ember-rollup.svg)](https://www.npmjs.com/package/ember-rollup) [![Build Status](https://travis-ci.org/asakusuma/ember-rollup.svg?branch=master)](https://travis-ci.org/asakusuma/ember-rollup)
2Use rollup to add runtime dependencies to an ember-cli addon.
3
4
5## Installation
6
7```
8npm i --save ember-rollup
9```
10
11
12## What is this thing?
13
14`ember-rollup` is not an addon, but rather a function that takes just two arguments:
15
16* An array of string module names. These modules must be present in `dependencies` in `package.json`.
17* The original object to be exported in `index.js`
18
19Simply wrap the exports of your app/addon `index.js` with the function, and suddenly, ES6/2015 dependencies in your ember app! `ember-rollup` even handles [babel](http://babeljs.io/) for you. Modules are namespaced based on the addon name.
20
21`ember-rollup` looks for a `jsnext:main` or `module` in `package.json` of imported modules. If not provided, it will fallback to `main` and assume a normal CommonJS module. If `main` is not provided, it will assume `index.js`.
22
23
24## Example
25
26```JavaScript
27//my-addon/index.js
28const emberRollup = require('ember-rollup');
29const runtimeDependencies = ['my-module', 'rsvp'];
30
31module.exports = emberRollup(runtimeDependencies, {
32 name: 'my-addon',
33 ...
34});
35```
36
37```JavaScript
38//my-addon/app/my-thing.js
39import myModule from 'my-addon/my-module';
40import RSVP from 'my-addon/rsvp';
41```
42
43
44## Custom Rollup Entry
45
46Some packages don't specify `jsnext:main` or `module` in their `package.json` even though
47a module exists. You can manually point rollup to the module entry point file path using `rollupEntry`.
48
49```JavaScript
50//my-addon/index.js
51const emberRollup = require('ember-rollup');
52const runtimeDependencies = [{
53 name: '@reactivex/rxjs',
54 namespaced: false,
55 rollupEntry: 'dist/esm5_for_rollup/index.js'
56}];
57
58module.exports = emberRollup(runtimeDependencies, {
59 name: 'my-addon',
60 ...
61});
62```
63
64```JavaScript
65//my-addon/app/my-thing.js
66import { Observable } from 'rxjs';
67```
68
69
70## Turning off addon namespacing
71
72By default, module names are namespaced based on the addon. The reason being, an app might use two different addons that require two different versions of the same module. If you would rather force the app to only include one version of any given module, you can turn off namespacing.
73
74```JavaScript
75//my-addon/index.js
76const emberRollup = require('ember-rollup');
77const runtimeDependencies = [{
78 name: 'my-module',
79 namespaced: false
80}, 'rsvp'];
81
82module.exports = emberRollup(runtimeDependencies, {
83 name: 'my-addon',
84 ...
85});
86```
87
88```JavaScript
89//my-addon/app/my-thing.js
90import myModule from 'my-module';
91import RSVP from 'my-addon/rsvp';
92```