React-app-rewired: How to customize babel with react-scripts v1 (webpack v2)

Created on 11 Jun 2017  路  4Comments  路  Source: timarney/react-app-rewired

before:

// config-overrides.js

function rewire(config, env) {
  const babelrc = config.module.loaders.find(conf => {
    return conf.loader === 'babel'
  }).query
  babelrc.plugins = [
    'styled-jsx-postcss/babel',
  ].concat(babelrc.plugins || [])
  return config
}

module.exports = rewire

after:

// config-overrides.js

function rewire(config, env) {
  const babelOptions = config.module.rules.find(conf => {
    return conf.loader && conf.loader.includes('babel-loader')
  }).options
  const babelrc = require(babelOptions.presets[0])
  babelrc.plugins = [
    'styled-jsx-postcss/babel',
  ].concat(babelrc.plugins || [])
  babelOptions.presets = babelrc
  return config
}

module.exports = rewire

happy coding!

Most helpful comment

@comerc @mauriciosoares

You should be able to use injectBabelPlugin(pluginName, config) now.

See the config here https://github.com/timarney/mobx-rewire-test/blob/master/config-overrides.js

Will add to the Readme at some point.

All 4 comments

images-1

@comerc @mauriciosoares

You should be able to use injectBabelPlugin(pluginName, config) now.

See the config here https://github.com/timarney/mobx-rewire-test/blob/master/config-overrides.js

Will add to the Readme at some point.

@timarney how about array of plugins? :)

@comerc Feel free to give it a try you can find the code here https://github.com/timarney/react-app-rewired/blob/master/packages/react-app-rewired/index.js

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ljxyweb picture ljxyweb  路  4Comments

huygn picture huygn  路  3Comments

InsOpDe picture InsOpDe  路  5Comments

srhise picture srhise  路  5Comments

windhost picture windhost  路  5Comments