Git Product home page Git Product logo

react-app-rewire-babel-loader's Introduction

react-app-rewire-babel-loader npm version

Rewire babel-loader loader in your create-react-app project using react-app-rewired.

Say there is an awesome library you found on npm that you want to use within your un-ejected create-react-app project, but unfortunately, it's published in ES6+ (since node_modules doesn't go through babel-loader), so you cannot really use it.

However, with react-app-rewired and this library, react-app-rewire-babel-loader, you can use that awesome library you've found.

See below for usage.

๐Ÿšจ Not maintained for react-app-rewired v2.x.x+

I'm not maintaining this library for react-app-rewired v2.x.x+.

Instead, please consider using: https://github.com/arackaf/customize-cra

The following essentially emulates react-app-rewire-babel-loader which you can copy & paste into your override config file:

// NOTE as of customize-cra v0.2.11

const { babelInclude, getBabelLoader } = require("customize-cra");

const include = (config, ...includes) => {
    return babelInclude(includes)(config);
};

const babelExclude = exclude => config => {
  getBabelLoader(config).exclude = exclude;
  return config;
};

const exclude = (config, ...excludes) => {
    return babelExclude(excludes)(config);
};

Install

$ yarn add react-app-rewire-babel-loader
# npm v5+
$ npm install react-app-rewire-babel-loader
# before npm v5
$ npm install --save react-app-rewire-babel-loader

Usage

// config-overrides.js
// see: https://github.com/timarney/react-app-rewired

const path = require("path");
const fs = require("fs");

const rewireBabelLoader = require("react-app-rewire-babel-loader");

// helpers

const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);

module.exports = function override(config, env) {

  // white-list some npm modules to the babel-loader pipeline
  // see: https://webpack.js.org/configuration/module/#rule-include

  config = rewireBabelLoader.include(
    config,
    resolveApp("node_modules/isemail")
  );

  // black-list some modules from the babel-loader pipeline
  // see: https://webpack.js.org/configuration/module/#rule-exclude

  config = rewireBabelLoader.exclude(
    config,
    /(node_modules|bower_components)/
  );

  return config;

};

Development

Chores

  • Lint: yarn run lint
  • Prettier: yarn run pretty
  • Test: yarn run test
  • Pre-publish: yarn run prepublish
  • Build: yarn run build

License

MIT.

react-app-rewire-babel-loader's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-app-rewire-babel-loader's Issues

Update library for react-app-rewired >= 2.0.0

Can this be updated for [email protected]? I am using it in a project that relies on latest version of react-app-rewired but npm gives me the warning
npm WARN [email protected] requires a peer of react-scripts@^1.0.14 but none is installed. You must install peer dependencies yourself. obviously because of react-app-rewire-babel-loader's dependencies.

I am more than happy to do it myself but I am not sure what is really needed for this to work with react-app-rewired >= 2.0.0. I've been using it for a while and haven't seen any problem loading new libraries.

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.