1

I have one cli project and one boilerplate project. Now I want to install all babel plugins and presets inside the cli, and use the cli to transpile the boilerplate.

The problem is, I'd like to run cli commands in boilerplate directory, and babel always looks for plugins/presets from boilerplate/node_modules instead of cli/node_modules.

How can I config babel to search only cli/node_modules? I've tried to set sourceRoot and moduleRoot, but neither work.

loganfsmyth
  • 156,129
  • 30
  • 331
  • 251
gocreating
  • 161
  • 2
  • 9

1 Answers1

2

You can explicitly pass the resolved plugins, e.g.

transform(code, {
    preset: [require('babel-preset-es2015')],
});
loganfsmyth
  • 156,129
  • 30
  • 331
  • 251
  • I don't suppose there is a way to do this with a `.babelrc`? I'm sure when babel 7 comes out it will allow this syntax in `.babelrc.js`, but until then is there any way to solve this? – trysis Sep 29 '17 at 19:55
  • If you've got a `.babelrc` in a project, that means the babel config is local to that project. You could make your own preset to do the resolution here, and then have the `.babelrc` load that preset though. – loganfsmyth Sep 29 '17 at 20:50