Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

customize-cra

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

customize-cra - npm Package Compare versions

Comparing version 0.1.0-beta3 to 0.1.0-beta4

28

index.js

@@ -17,17 +17,19 @@ const curry = require("lodash.curry");

const addBabelPlugin = plugin => config => {
let rulesWithBabel = config.module.rules.filter(
r => r.oneOf && r.oneOf.some(r => Array.isArray(r.use) && r.use.some(u => u.options && u.options.babelrc != void 0))
);
const babelLoaderFilter = rule => rule.loader && rule.loader.includes("babel") && rule.options && rule.options.plugins;
for (let rb of rulesWithBabel) {
for (let r of rb.oneOf) {
if (r.use) {
for (let u of r.use) {
if (u.options && u.options.babelrc != void 0) {
u.options.plugins = (u.options.plugins || []).concat([plugin]);
}
}
}
}
// First, try to find the babel loader inside the oneOf array.
// This is where we can find it when working with react-scripts@2.0.3.
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 react-scripts@2.0.0.next.* versions.
if (!babelLoader) {
loaders = loaders.reduce((ldrs, rule) => ldrs.concat(rule.use || []), []);
babelLoader = loaders.find(babelLoaderFilter);
}
babelLoader.options.plugins.push(plugin);
return config;

@@ -34,0 +36,0 @@ };

{
"name": "customize-cra",
"version": "0.1.0-beta3",
"version": "0.1.0-beta4",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -7,3 +7,3 @@ # customize-cra

The functions documented below can be imported by name, and used in your config-overrides.js file, ie
The functions documented below can be imported by name, and used in your `config-overrides.js` file, as explained below.

@@ -21,37 +21,44 @@ ```js

## Docs
## Available plugins
### addBabelPlugin(plugin, config)
### addBabelPlugin(plugin)
Adds a babel plugin. Not sure what else to say here.
### addDecoratorsLegacy(config)
### addDecoratorsLegacy()
Add decorators in legacy mode. Be sure to have `@babel/plugin-proposal-decorators` installed.
### disableEsLint(config)
### disableEsLint()
Does what it says. You may need this along with `addDecoratorsLegacy` in order to get decorators and exports to parse together.
### addWebpackAlias(alias, config)
### addWebpackAlias(alias)
Adds the provided alias info into webpack's alias section. Pass an object literal with as many entries as you'd like, and the whole object will be merged in.
### addBundleVisualizer(config)
### addBundleVisualizer()
Adds the bundle visualizer plugin to your webpack config. Be sure to have `webpack-bundle-analyzer` installed.
## MobX Users
## Using the plugins
If you want CRA 2 to work with MobX, this should get you going.
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. This means that if you need to conditionally apply any of these plugins, just provide a lambda that receives the config object, and conditionally invoke a plugin as needed, being sure to call it twice.
For example
```js
const { addDecoratorsLegacy, disableEsLint } = require("customize-cra");
const { override, addDecoratorsLegacy, disableEsLint, addBundleVisualizer, addWebpackAlias } = require("customize-cra");
const path = require("path");
module.exports = function override(config) {
addDecoratorsLegacy(config);
disableEsLint(config);
module.exports = override(
addDecoratorsLegacy(),
disableEsLint(),
config => (process.env.BUNDLE_VISUALIZE == 1 ? addBundleVisualizer()(config) : config),
addWebpackAlias({ ["ag-grid-react$"]: path.resolve(__dirname, "src/shared/agGridWrapper.js") })
);
```
return config;
};
```
## MobX Users
If you want CRA 2 to work with MobX, use the `addDecoratorsLegacy` and `disableEsLint`.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc