Giter Club home page Giter Club logo

customize-cra's Introduction

customize-cra

All Contributors

πŸ“ŒπŸ“Œ Breaking change: With the 1.0 release of customize-cra breaking changes have been made to the addLessLoader customizer to support the changes to create-react-app in #7876. Please follow the migration guide in #253.

This project provides a set of utilities to customize create-react-app versions 2 and 3 configurations leveraging react-app-rewired core functionalities.

How to install

This project relies on react-app-rewired. You'll need to install that in order for customize-cra to work.

yarn add customize-cra react-app-rewired --dev

❗ Warning

"Stuff can break" - Dan Abramov

Using this library will override the default behavior and configuration of create-react-app, therefore invalidating the guarantees that come with it. Use with discretion!

Overview

customize-cra takes advantage of react-app-rewired's config-overrides.js file. By importing customize-cra functions and exporting a few function calls wrapped in our override function, you can easily modify the underlying config objects (webpack, webpack-dev-server, babel, etc.) that make up create-react-app.

Usage

Note: all code should be added to config-overrides.js at the same level as package.json.

See the api docs for documentation for each function.

With webpack

To use these plugins, import the override function, and call it with whatever plugins you need. Each of these plugin invocations will return a new function, that override will call with the newly modified config object. Falsy values will be ignored though, so if you need to conditionally apply any of these plugins, you can do so like below.

For example:

const {
  override,
  addDecoratorsLegacy,
  disableEsLint,
  addBundleVisualizer,
  addWebpackAlias,
  adjustWorkbox
} = require("customize-cra");
const path = require("path");

module.exports = override(
  // enable legacy decorators babel plugin
  addDecoratorsLegacy(),

  // disable eslint in webpack
  disableEsLint(),

  // add webpack bundle visualizer if BUNDLE_VISUALIZE flag is enabled
  process.env.BUNDLE_VISUALIZE == 1 && addBundleVisualizer(),

  // add an alias for "ag-grid-react" imports
  addWebpackAlias({
    ["ag-grid-react$"]: path.resolve(__dirname, "src/shared/agGridWrapper.js")
  }),

  // adjust the underlying workbox
  adjustWorkbox(wb =>
    Object.assign(wb, {
      skipWaiting: true,
      exclude: (wb.exclude || []).concat("index.html")
    })
  )
);

With webpack-dev-server

You can use the overrideDevServer function to override the webpack-dev-server config. It works the same way as override:

const {
  override,
  disableEsLint,
  overrideDevServer,
  watchAll
} = require("customize-cra");

module.exports = {
  webpack: override(
    // usual webpack plugin
    disableEsLint()
  ),
  devServer: overrideDevServer(
    // dev server plugin
    watchAll()
  )
};

With MobX

If you want CRA 2 to work with MobX, use the addDecoratorsLegacy and disableEsLint.

Documentation

See api.md for documentation on the functions provided by customize-cra.

Contributing

For more information about contributing to this project, like a directory map or a how-to for reporting an issue about the project, please see contributing.md.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

dqu
dqu

πŸ’¬
Breeze
Breeze

πŸ’»
Terryand
Terryand

πŸ’»
m-weeks
m-weeks

πŸ›
吴袅
吴袅

πŸ’‘
James Thistlewood
James Thistlewood

πŸ’»
taddj
taddj

πŸ’¬
MeiLin
MeiLin

πŸ’»
Graham Crockford
Graham Crockford

πŸ€”
afei
afei

πŸ’»
zoomdong
zoomdong

πŸ’»
Danilo Campana Fuchs
Danilo Campana Fuchs

πŸ’»
Rodrigo Narvaez
Rodrigo Narvaez

πŸ’»
blackmatch
blackmatch

πŸ’»
billypon
billypon

πŸ’»
Juetta
Juetta

πŸ’»
LING_ZI_QING
LING_ZI_QING

πŸ’» πŸ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

customize-cra's People

Contributors

with-heart avatar arackaf avatar fezvrasta avatar onlyling avatar zhigang1992 avatar anish-agnihotri avatar dependabot[bot] avatar liyuanqiu avatar terryand avatar oshotokill avatar rasmusbe avatar oknoorap avatar rodrigonarvaez avatar shanecav avatar xueqingxiao avatar vferdiansyah avatar gfafei avatar billypon avatar blackmatch avatar edwardwang0302 avatar lf7817 avatar mushan0x0 avatar fireairforce avatar postgetme avatar kitze avatar kevincolten avatar 1123612483 avatar jthistle avatar hsz avatar jcofman avatar

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.