All Projects โ†’ monkey-patches โ†’ monkey-react-scripts

monkey-patches / monkey-react-scripts

Licence: MIT license
Monkey react script runner

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to monkey-react-scripts

cra-macro-example
This is an example of how you can use Create React App with Babel Plugin Macros.
Stars: โœญ 38 (+72.73%)
Mutual labels:  create-react-app
spax
[WIP] ๐Ÿš€ a framework for building frameworks
Stars: โœญ 22 (+0%)
Mutual labels:  react-scripts
manifest
This is where the magic begins
Stars: โœญ 29 (+31.82%)
Mutual labels:  custom
cra-tailwindcss-in-js
Integrate Tailwind CSS in a Create React App setup using css-in-js solutions
Stars: โœญ 35 (+59.09%)
Mutual labels:  create-react-app
create-react-scripts
Easily extend the react-scripts to your own version of react-scripts
Stars: โœญ 64 (+190.91%)
Mutual labels:  create-react-app
react-reactions
๐Ÿ˜ฒ Create custom reaction pickers and counters or use your favorites!
Stars: โœญ 34 (+54.55%)
Mutual labels:  custom
public-ol-web-template
OrangeLoops Web Project Boilerplate
Stars: โœญ 28 (+27.27%)
Mutual labels:  create-react-app
create-cra-template
A cli tool to generate cra-template from current create-react-app project.
Stars: โœญ 22 (+0%)
Mutual labels:  create-react-app
uptime-card
Minimalistic uptime card for Home Assistant Lovelace UI
Stars: โœญ 152 (+590.91%)
Mutual labels:  custom
basic-todo-app-using-bit
A highly-modular React todo application composed of reusable components from 5 different collections. Full-blown software modularity.
Stars: โœญ 16 (-27.27%)
Mutual labels:  create-react-app
react-firebase-template
Bootstrap a React + Firebase full stack application with every thing you need pre-configured: hosting, database, authentication, CI, Typescript, Material UI, PWA and other goodies.
Stars: โœญ 24 (+9.09%)
Mutual labels:  create-react-app
cra-bundle-analyzer
Use Webpack Bundle Analyzer on a create-react-app application without ejecting
Stars: โœญ 46 (+109.09%)
Mutual labels:  create-react-app
crassa
Create React App Server Side Application
Stars: โœญ 16 (-27.27%)
Mutual labels:  create-react-app
GraphQL-Blueprint
GraphQL Blueprint: a software developer tool for engineers that want to quickly generate React/Express, Apollo and GraphQL boilerplate code using a data modeling interface. Watch your queries, mutations, and schema update in realtime with our code preview feature and finally, export it when you're ready to begin building the rest of your app!
Stars: โœญ 74 (+236.36%)
Mutual labels:  create-react-app
react-antd-admin
ๅŸบไบŽvite2.x + react17.x + typescript4.x + antd4.x + react-router6.x + mobx6.x็ผ–ๅ†™็š„ไธ€ๆฌพ็ฎ€ๅ•้ซ˜ๆ•ˆ็š„ๅ‰ๅŽ็ซฏๅˆ†็ฆป็š„ๆƒ้™็ฎก็†็ณป็ปŸ
Stars: โœญ 140 (+536.36%)
Mutual labels:  create-react-app
react-intl.macro
Extract react-intl messages with babel-plugin-macros.
Stars: โœญ 39 (+77.27%)
Mutual labels:  create-react-app
cra-and-storybook
Stars: โœญ 13 (-40.91%)
Mutual labels:  create-react-app
RMGradientView
A Custom Gradient View Control for iOS with inspectable properties.
Stars: โœญ 24 (+9.09%)
Mutual labels:  custom
descent-app
Top of descent path calculator. Let's calculate your descent!
Stars: โœญ 28 (+27.27%)
Mutual labels:  create-react-app
google-place-autocomplete
๐Ÿ† Best practice with Google Place Autocomplete API onย React
Stars: โœญ 68 (+209.09%)
Mutual labels:  create-react-app

monkey-react-scripts

Monkey react script runner: Customize react-scripts webpack config without eject or fork

Many of you want to add a small change to your webpack config created by create-react-app. but you don't want to eject. or use other scripts like configurable-react-scripts or custom-react-scripts because of update delay.

With monkey-react-scripts you can use react-scripts configs, but monkey patched one. so you always have updated react-scripts.

โ˜ข DANGER โ˜ข

As @gaearon mentioned multiple times there, it's not good idea to extend it. From my point of view, I'm giving you gun, so try not to shot yourself, because probably nobody will help you. When you modify something, be completely sure what you doing!

source

Usage

  • use create-react-app and create your project, more detail
npm install -g create-react-app

create-react-app my-app
cd my-app/
  • install monkey-react-scripts
npm install monkey-react-scripts --save-dev --save-exact
  • create webpack.monkey.js in the root of your project. you can modify webpack config here.
module.exports = function(webpackConfig, isDevelopment) {
  // mutate webpackConfig
};
  • edit package.json and replace scripts
  "scripts": {
    "start": "monkey-react-scripts start",
    "build": "monkey-react-scripts build",
    "test": "monkey-react-scripts test"
  }

How it works

I suggest you see scripts and bin folders. (less than 100 line of code)

Note: returned value of require function is mutable. so you can mutate that before real build/start script.

Snippets

You can use snippets if you want.

snippets:

  • addPlugin
  • findRule
  • findBabelRule

Example

Before use examples, you should know what happens inside react-scripts webpack config. first, see and read this files:

  • node_modules/react-scripts/config/webpack.config.dev.js
  • node_modules/react-scripts/config/webpack.config.prod.js

also, you can log webpackConfig value.

// webpack.monkey.js
module.exports = function(webpackConfig, isDevelopment) {
  console.log(webpackConfig);
};

Also, you can find complete examples at monkey-react-scripts-example repo

Enable .babelrc

The .babelrc file is enabled for tests if you have webpack.monkey.js file. also, you can enable .babelrc for build and start:

  • edit webpack.monkey.js like this (copy findRule, findBabelRule from snippets):
function findRule(webpackConfig, callback) {
  /* snippet codes */
}

function findBabelRule(webpackConfig, callback) {
  /* snippet codes */
}

module.exports = function(webpackConfig, isDevelopment) {
  const babelRule = findBabelRule(webpackConfig);
  babelRule.options.babelrc = true;
};

Webpack Visualizer

I love visualization so, I add webpack-visualizer-plugin to my project

  • install plugin:
npm install webpack-visualizer-plugin --save-dev
  • add the plugin to config (only at build time)
// webpack.monkey.js
var Visualizer = require("webpack-visualizer-plugin");

module.exports = function(webpackConfig, isDevelopment) {
  if (!isDevelopment) {
    webpackConfig.plugins.push(new Visualizer());
  }
};
  • build
$ npm run build
// some output
$ tree build
build
โ”œโ”€โ”€ asset-manifest.json
โ”œโ”€โ”€ favicon.ico
โ”œโ”€โ”€ index.html
โ”œโ”€โ”€ static
โ”‚   โ”œโ”€โ”€ css
โ”‚   โ”œโ”€โ”€ js
โ”‚   โ””โ”€โ”€ media
โ””โ”€โ”€ stats.html                      <-- new file

Decorator support

If you love decorators, you can add decorator support:

  • install decorator plugin
npm install --save-dev @babel/plugin-proposal-decorators
  • edit .babelrc like this:
{
  "plugins": [["@babel/plugin-proposal-decorators", { "legacy": true }]]
}

related issues: #107, #167, #214, #309, #411, #1357

Relay support

  • install babel-plugin-relay
yarn add --dev babel-plugin-relay
  • edit .babelrc like this:
{
  "plugins": ["relay"]
}

and continue relay documentation steps.

if you are using relay classic you can see old readme and get some ideas.

related issues: #462, #662, #900

postcss config

If you want to change postcss config you can use this code.

// add rtl css support
// find postCssLoader
const postCssFunction = postCssLoader.options.plugins;
postCssLoader.options.plugins = () => {
  return [...postCssFunction(), require("postcss-inline-rtl")];
};

you can find more detail in this file

TODOs

  • customize test runner (jest)
  • add more example
    • relay support

compatibility

react-scripts monkey-react-scripts
0.9.x 0.0.5
1.x.x 0.1.0
2.0.0 - 2.1.1 0.1.2
2.1.2 0.1.4
3.0.0 0.2.0
4.0.0 0.3.0
5.0.0 5.0.0-0

Thanks

@svrcekmichal for configurable-react-scripts

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].