# ember-cli-cjs-transform

> Add a CJS tranform for use with ember-cli's `app.import` API.

Latest version **2.0.0** (published 2019-02-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install ember-cli-cjs-transform
pnpm add ember-cli-cjs-transform
yarn add ember-cli-cjs-transform
bun add ember-cli-cjs-transform
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2019-02-21 |
| First published | 2017-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | ^4.5 \|\| 6.* \|\| >= 7.* |
| Dependencies | 12 |
| Unpacked size | 10.4 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 48 |
| Author | Robert Jackson |
| Maintainers | rwjblue |
| Keywords | ember-addon |

## Links

- npm: https://www.npmjs.com/package/ember-cli-cjs-transform
- Repository: git@github.com:rwjblue/ember-cli-cjs-transform
- npm.io page: https://npm.io/package/ember-cli-cjs-transform

## Dependencies (12)

- [rollup](https://npm.io/package/rollup.md) ^1.1.2
- [pkg-dir](https://npm.io/package/pkg-dir.md) ^3.0.0
- [resolve](https://npm.io/package/resolve.md) ^1.7.1
- [fs-extra](https://npm.io/package/fs-extra.md) ^7.0.1
- [username](https://npm.io/package/username.md) ^4.0.0
- [hash-for-dep](https://npm.io/package/hash-for-dep.md) ^1.2.3
- [broccoli-debug](https://npm.io/package/broccoli-debug.md) ^0.6.4
- [broccoli-plugin](https://npm.io/package/broccoli-plugin.md) ^1.3.0
- [ember-cli-babel](https://npm.io/package/ember-cli-babel.md) ^7.1.2
- [sync-disk-cache](https://npm.io/package/sync-disk-cache.md) ^1.3.3
- [rollup-plugin-commonjs](https://npm.io/package/rollup-plugin-commonjs.md) ^9.1.0
- [rollup-plugin-node-resolve](https://npm.io/package/rollup-plugin-node-resolve.md) ^4.0.0

## Recent versions

- 2.0.0 (latest) — 2019-02-21
- 1.3.1 — 2019-02-21
- 1.3.0 — 2018-06-01
- 1.2.0 — 2018-04-23
- 1.1.1 — 2018-03-23
- 1.1.0 — 2018-03-23
- 1.0.0 — 2017-11-17

## README

# ember-cli-cjs-transform

This addon allows importing files that are in the CommonJS format via the
standard `app.import` functionality added in ember-cli 2.16.

## Installing

```
ember install ember-cli-cjs-transform
```

## Usage

In your `ember-cli-build.js` file just like the `amd` transform!

For example, add the following to import `some-name`'s `index.js` into your build:

```js
app.import('node_modules/some-name/index.js', {
  using: [
    { transformation: 'cjs', as: 'some-name'}
  ]
});
```

At build time we automatically follow all dependencies (e.g. internal `require`
calls) in the source file, and includes their contents in the final build
output.

This means that even for reasonably complicated things, we can `app.import` the
"entry point" files and everything "just" works.

Examples (used while testing functionality):

Bringing in `showdown` and `showdown-highlight` for usage (without extra "shim" addon packages!):

```js
app.import('node_modules/showdown/dist/showdown.js', {
  using: [{ transformation: 'cjs', as: 'showdown' }]
});
app.import('node_modules/showdown-highlight/lib/index.js', {
  using: [{ transformation: 'cjs', as: 'showdown-highlight' }]
});
app.import('node_modules/highlight.js/styles/tomorrow-night.css');
```

There may be cases where you need additional rollup plugins in order to import your CommonJs files. For example, you may need to handle builtin node require statements, i.e.

```
var path = require('path');
```

For this, you may want to import the rollup plugin `rollup-plugin-node-builtins`. In order to do this, include the plugin in your `package.json` and use the following syntax in your `ember-cli-build.js` or `index.js`:

```js
const nodeBuiltins = require('rollup-plugin-node-builtins');

app.import('node_modules/some-name/index.js', {
  using: [
    { transformation: 'cjs', as: 'some-name', plugins: [ nodeBuiltins() ]}
  ]
});
```

You can include multiple rollup plugins in the array and pass in options via the arguments to your plugin creation function.

```js
app.import('node_modules/some-name/index.js', {
  using: [
    {
      transformation: 'cjs',
      as: 'some-name',
      plugins: [
        plugin1(),
        plugin2({ option1: "value" })
      ]
    }
  ]
});
```

## Contributing

### Installation

* `git clone <repository-url>` this repository
* `cd ember-cli-cjs-transform`
* `yarn install`

### Running

* `ember serve`
* Visit your app at [http://localhost:4200](http://localhost:4200).

### Running Tests

* `yarn test` (Runs `ember try:each` to test your addon against multiple Ember versions)
* `ember test`
* `ember test --server`

### Building

* `ember build`

For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).

---
_Source: https://npm.io/package/ember-cli-cjs-transform · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
