babel / duo-babel

Duo plugin for Babel
15 stars 14 forks source link

Adding "only" and "ignore" support #9

Closed dominicbarnes closed 9 years ago

dominicbarnes commented 9 years ago

This addresses #8 by adding proper support for the only and ignore configuration options. In some cases, transpilation can be undesired:

Anyways, the point is the ability to be more deliberate about what should and should not be transpiled is quite useful. (this does away with the onlyLocals option, as this syntax is far more flexible)

var babel = require('duo-babel');

// default behavior, transpile all the things
duo.use(babel());

// only process locals (identical to the old onlyLocals config)
duo.use(babel({
  only: [ 'locals' ]
}));

// whitelist locals and certain remotes
duo.use(babel({
  only: [ 'locals', 'components/segmentio-*/**.js' ]
}));

// blacklist certain locals and remotes
duo.use(babel({
  ignore: [ 'lib/react.js', 'components/lodash*/**.js' ]
}));

Notice, we are taking advantage of the directory structure that duo creates, as babel already has a pretty robust system internally. We only added some sugar here for our special cases. (ie: "locals" and "remotes")