babel / babel-brunch

Brunch plugin for Babel
ISC License
69 stars 38 forks source link

Cannot use plugin or preset options #37

Closed razor-x closed 7 years ago

razor-x commented 7 years ago

I believe these lines:

const mappedPresets = opts.presets.map(ps => resolve(config.paths.root, 'node_modules', `babel-preset-${ps}`));
const mappedPlugins = opts.plugins.map(pg => resolve(config.paths.root, 'node_modules', `babel-plugin-${pg}`));

means that setting plugin or preset options is not supported, e.g.,

{
  "plugins": [
    ["transform-async-to-module-method", {
      "module": "bluebird",
      "method": "coroutine"
    }]
  ]
}

{
  "presets": [
    ["es2015", { "loose": true, "modules": false }]
  ]
}

as ${ps} would resolve to ["es2015", { "loose": true, "modules": false }].

Trying to set options fails with an Unknown plugin error.

razor-x commented 7 years ago

Quick followup: it seems preset options are working correctly (maybe someone can confirm this), but plugin options fail:

15 Aug 16:59:31 - error: Compiling of app/constants/messages/index.js failed. Unknown plugin "/<FULL_PATH>/node_modules/babel-plugin-transform-async-to-module-method,[object Object]" specified in "base" at 0, attempted to resolve relative to "app/constants/messages" 

This is testing with the above plugin config example above inside package.json.

razor-x commented 7 years ago

Quick attempt at handling options (added an extra test): https://github.com/rxfork/babel-brunch/commit/afb0083ef65f02165be5eae63ec90a1f0109b4da

Should we have test coverage for presets and plugins given in both forms and check the options actually get handled by babel? Would need to depend on some presets / plugins that actually have extra options to test that.