0.0.1 • Published 8 years ago
babel-node-modules v0.0.1
babel node_modules
simple wrapper for babel-register to make including ES6 modules easier
Installation
$ npm install --save-dev babel-node-modules
...or:
$ yarn add --dev babel-node-modules
Motivation
This is for making the process of using ES6/ES2015 modules (using import
syntax rather than CommonJS's require
style) in projects easier, especially when testing, which can be a bit of a nightmare. This is specifically for when an ES6 module has been installed via npm or yarn and resides somewhere in your node_modules/
directory.
Usage
First write your test file in ES6/ES2015, including import
ing any ES6/ES2016 modules.
test/test.js
import assert from 'assert'
import {hello} from 'helloworld'
describe('if this works, everything compiled fine', () => {
it('string should match', () => {
assert(hello() === 'hello stranger!')
assert(hello('John') === 'hello John!')
})
})
test/node_modules/helloworld/world.js
export function hello (name = 'stranger') {
return `hello ${name}!`
}
test/node_modules/helloworld/package.json
{
"name": "helloworld",
"main": "world.js"
}
test/testPolyfill.js
require('babel-node-modules')([
'helloworld' // add an array of module names here
])
...then run your tests:
$ mocha --require test/testPolyfill.js
0.0.1
8 years ago