generator-babel
v2.0.2
Published
Yeoman generator to setup Babel effortlessly (with plugins, if you want)
Downloads
37
Maintainers
Readme
generator-babel
Yeoman generator to setup Babel effortlessly (with plugins, if you want).
Works great as cli and with other generators too.
By default, Babel doesn’t do anything! You need to configure it. So this package will create Babel’s configuration file .babelrc
with default es2015
preset and install required babel-cli
, babel-core
to devDependencies in your project.
After this package’s work is finished, you can access babel-cli
and babel-register
from your npm scripts. It’s useful for:
- transpilation:
babel index.js --out-file index.es5.js
- testing via hook:
mocha --require babel-register
,tape test.js --require babel-register
, etc.
Install
npm install --global yo generator-babel
Usage
# default es2015 preset
yo babel
# your favorite presets
yo babel es2015 stage-0
# with plugins with --plugins/-p
yo babel -p add-module-exports
yo babel -p transform-strict-mode,transform-object-assign
The entire range of Babel presets are allowed.
Composability
Composability is a way to combine smaller parts to make one large thing. Sort of like Voltron®
— Yeoman docs
Just plug in babel into your generator and let it setup your .babelrc
and install required devDependencies
for you. Everybody wins.
Install
npm install --save generator-babel
Compose
skip-install
is used because babel
install babel deps for you
and you don’t need to test it in your own generator tests.
this.composeWith('babel', { options: {
'skip-install': this.options['skip-install']
}}, {
local: require.resolve('generator-babel/generators/app')
});
Add any extra fields you need to options.config
to extend the default configuration. The entire range of Babel options are allowed.
this.composeWith('babel', { options: {
'skip-install': this.options['skip-install'],
config: {
presets: ['es2015', 'stage-0'],
plugins: ['transform-strict-mode', 'transform-object-assign'],
sourceMaps: true
}
}}, {
local: require.resolve('generator-babel')
});
Required list of presets
and plugins
will be installed to devDependencies
into your project with proper names: es2015
will be babel-preset-es2015
and transform-strict-mode
will be babel-plugin-transform-strict-mode
.
License
MIT © Vladimir Starkov