Code Monkey home page Code Monkey logo

Comments (6)

ltkn avatar ltkn commented on July 28, 2024

the issue might be the declaration here 57bb094#diff-168726dbe96b3ce427e7fedce31bb0bcR16

from customize-cra.

walmor avatar walmor commented on July 28, 2024

I was facing the same issue and I did a little further investigation to understand the problem. Hope that can help.

I was using the react-scripts version 2.0.3, that was released two days ago (Oct, 1th). The PR #5170 was merged two days before the release, where they removed the thread-loader. That PR changed the shape of the configuration object, removing the use array from the babel loader rule.

That means that the current version of the customize-cra works well for [email protected].* versions but it doesn't work for the version 2.0.3.

To avoid a breaking change for the users using versions 2.0.0, I came up with a version of the addBabelPlugin that is able to handle both versions.

function addBabelPlugin(plugin, config, env) {
  const babelLoaderFilter = rule =>
    rule.loader && rule.loader.includes('babel') && rule.options && rule.options.plugins;

  // First, try to find the babel loader inside the oneOf array.
  // This is where we can find it when working with [email protected].
  let loaders = config.module.rules.find(rule => Array.isArray(rule.oneOf)).oneOf;

  let babelLoader = loaders.find(babelLoaderFilter);

  // If the loader was not found, try to find it inside of the "use" array, within the rules.
  // This should work when dealing with [email protected].* versions.
  if (!babelLoader) {
    loaders = loaders.reduce((ldrs, rule) => ldrs.concat(rule.use || []), []);
    babelLoader = loaders.find(babelLoaderFilter);
  }

  babelLoader.options.plugins.push(plugin);

  return config;
}

That code is not fully tested. I've only done some simple test against the versions 2.0.3 and 2.0.0-next.fb6e6f70 (the lastest 2.0.0.next.* version). Probably more tests would be necessary before using it as the actual implementation.

from customize-cra.

war3k avatar war3k commented on July 28, 2024

try to use my fork :
https://github.com/war3k/customize-cra

from customize-cra.

priezz avatar priezz commented on July 28, 2024

@war3k Thanks, it works! You should probably send a PR with the changes given.

from customize-cra.

war3k avatar war3k commented on July 28, 2024

sure, I already did that :)

from customize-cra.

arackaf avatar arackaf commented on July 28, 2024

Seems Dan Abramov moved my cheese :P

@walmor's fix is updated for the new 0.1.X api, and released under 0.1.0-beta4.

from customize-cra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.