Skip to content

addBabelPlugin not inserting the plugin #4

@jgoux

Description

@jgoux

Hello,

the current implementation doesn't insert the plugin (in my case I tried with addBabelPlugin(['emotion'])(config)).

This doesn't match the babel-loader :

Array.isArray(r.use) && r.use.some(u => u.options && u.options.babelrc != void 0)

because the babel-loader doesn't have a use key.

The two characteristics I use to spot the right babel-loader (there are 2 of them) are :

  • The loader name contains "babel-loader"
  • It has a "customize" key
function addBabelPlugin(plugin) {
  return function(config) {
    const babelLoader = config.module.rules
      .find(rule => Object.keys(rule).includes('oneOf'))
      .oneOf.find(
        rule =>
          rule.loader &&
          rule.loader.includes('babel-loader') &&
          rule.options.customize
      )

    babelLoader.options.plugins.push(plugin)

    return config
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions