• Stars
    star
    2,778
  • Rank 16,396 (Top 0.4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Override webpack configurations for create-react-app 2.0

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!

More Repositories

1

micro-graphql-react

Light and simple GraphQL React client with extensible, composable cache invalidation. Works with Suspense.
JavaScript
528
star
2

mongo-graphql-starter

Creates a fully functioning, performant, extensible GraphQL endpoint from a Mongo DB. Supports middleware, Mongo 4 transactions.
JavaScript
424
star
3

booklist

A book tracking websiteβ€”my take LibraryThing.
JavaScript
262
star
4

svelte-helpers

A toolkit of (hopefully) useful Svelte utilities. Contains helpers for using spring animations in transitions, and a Modal component.
Svelte
54
star
5

micro-graphql-svelte

Light and simple GraphQL Svelte client with extensible, composable cache invalidation.
TypeScript
44
star
6

generic-persistgraphql

Reduce bundle size and bandwidth, while securing your backend by whitelisting valid queries and mutations.
JavaScript
25
star
7

easy-express-controllers

Add MVC style controllers to Express with class decorators.
JavaScript
19
star
8

preact-lightning-talk

JavaScript
12
star
9

my-blog

TypeScript
8
star
10

next-blurhash-previews

JavaScript
8
star
11

next-wc-ssr

JavaScript
7
star
12

simple-react-bootstrap

Simple and slim React bindings for those Bootstrap components which modify the DOM. Includes Modal, ButtonDropdown, and NavBar.
JavaScript
5
star
13

vscode-react-ecosystem-snippets

VS Code snippets for React development. Covers React, and its ecosystemβ€”for now just MobX.
JavaScript
4
star
14

okcjs-react-redux-talk

okc.js talk on react and redux
JavaScript
3
star
15

npm_sandbox

3
star
16

typescript-workshop

TypeScript
2
star
17

graphql-node-mssql

JavaScript
2
star
18

sveltekit-blog-1

JavaScript
2
star
19

rsc-sandbox

CSS
2
star
20

sveltekit-form-error-repro

JavaScript
2
star
21

svelte-kit-form-nav-repro

JavaScript
2
star
22

next-13-data-fetching-blog-post

TypeScript
2
star
23

next-13-data-fetching-blog

TypeScript
1
star
24

next-repro

JavaScript
1
star
25

vite-sandbox

JavaScript
1
star
26

booklist-desktop

C++
1
star
27

test-mongo-graphql-starter

JavaScript
1
star
28

graphql-talk

JavaScript
1
star
29

sveltekit-next-auth-post

TypeScript
1
star
30

booklist-ios

Swift
1
star
31

dynamo-adapter-edge-deploy-bug

JavaScript
1
star
32

dynamo-adapter-edge-deploy

JavaScript
1
star
33

sveltekit-blog-2-caching

JavaScript
1
star