![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
@craco/craco
Advanced tools
Readme
Create React App Configuration Override is an easy and comprehensible configuration layer for create-react-app v2.
Get all the benefits of create-react-app and customization without using 'eject' by adding a single craco.config.js
file at the root of your application and customize your eslint, babel, postcss configurations and many more.
All you have to do is create your app using create-react-app and customize the configuration with a craco.config.js
file.
craco
.Acknowledgements:
We are grateful to @timarney the creator of react-app-rewired for his original idea.
Also, please note that the configuration style of this plugin has been greatly influenced by the way Vue CLI does it.
Please Note:
By doing this you're breaking the "guarantees" that CRA provides. That is to say you now "own" the configs. No support will be provided. Proceed with caution.
Install the plugin from npm:
$ npm install @craco/craco --save-dev
Create a craco.config.js
file in the root directory:
my-app
âââ node_modules
âââ craco.config.js
âââ package.json
Export your configuration as an object literal:
/* craco.config.js */
module.exports = {
...
}
or a function:
/* craco.config.js */
module.exports = function({ env, paths }) {
return {
...
};
}
Update the existing calls to react-scripts
in the scripts
section of your package.json
file to use the craco
CLI:
/* package.json */
"scripts": {
- "start": "react-scripts start",
+ "start": "craco start",
- "build": "react-scripts build",
+ "build": "craco build"
}
Start your app for development:
$ npm start
Or build your app:
$ npm run build
When you execute craco start
or craco build
a few options are available.
To change the location of the configuration file:
"scripts": {
"start": "craco --config config/craco-config-with-custom-name.js"
}
To use a custom version of the react-scripts
packages:
"scripts": {
"start": "craco --react-scripts react-scripts-ts"
}
To activate verbose logging:
"scripts": {
"start": "craco --verbose"
}
When the property mode is available there are 2 possible values:
extends
: the provided configuration will extends the CRA settings (this is the default mode)file
: the CRA settings will be reseted and you will provide an official configuration file for the plugin (postcss, eslint) that will supersede any settings.const { paths, when, whenDev, whenProd, ESLINT_MODES, POSTCSS_MODES } = require("craco");
module.exports = {
style: {
modules: {
localIdentName: ""
},
css: {
loaderOptions: {} || (cssLoaderOptions, { env, paths }) => { return cssLoaderOptions; }
},
sass: {
loaderOptions: {} || (sassLoaderOptions, { env, paths }) => { return sassLoaderOptions; }
},
postcss: {
mode: "extends" || "file",
plugins: [],
loaderOptions: {} || (postcssLoaderOptions, { env, paths }) => { return postcssLoaderOptions; }
}
},
eslint: {
enable: true,
mode: "extends" || "file",
parserOptions: {},
env: {},
globals: [],
plugins: [],
extends: [],
rules: {},
formatter: "",
loaderOptions: {} || (eslintOptions, { env, paths }) => { return eslintOptions; }
},
webpack: {
alias: {},
plugins: []
},
configureWebpack: {} || (webpackConfig, { env, paths }) => { return webpackConfig; },
devServer: {},
babel: {
presets: [],
plugins: [],
loaderOptions: {} || (babelLoaderOptions, { env, paths }) => { return babelLoaderOptions; }
},
plugins: [
{
plugin: {
overrideCracoConfig: ({ cracoConfig, pluginOptions, context: { env, paths } }) => { return cracoConfig; },
overrideWebpackConfig: ({ webpackConfig, cracoConfig, pluginOptions, context: { env, paths } }) => { return webpackConfig; },
},
options: {}
}
]
};
There are 2 functions available to a plugin:
overrideCracoConfig
: Let a plugin customize the config object before it's process by craco
.overrideWebpackConfig
: Let a plugin customize the webpack
config that will be used by CRA.Important:
Every functions must return the updated config object.
The function overrideCracoConfig
let a plugin override the config object before it's process by craco
.
If a plugin define the function, it will be called with the config object read from the craco.config.js
file provided by the consumer.
The function must return a valid config object, otherwise craco
will throw an error.
The function will be called with a single object argument having the following structure:
{
cracoConfig: "The config object read from the craco.config.js file provided by the consumer",
pluginOptions: "The plugin options provided by the consumer",
context: {
env: "The current NODE_ENV (development, production, etc..)",
paths: "An object that contains all the paths used by CRA"
}
}
Plugin:
/* craco-plugin-log-craco-config.js */
module.exports = {
overrideCracoConfig: ({ cracoConfig, pluginOptions, context: { env, paths } }) => {
if (pluginOptions.preText) {
console.log(pluginOptions.preText);
}
console.log(JSON.stringify(craconfig, null, 4));
// Always return the config object.
return cracoConfig;
}
};
Registration (in a craco.config.js
file):
const logCracoConfigPlugin = require("./craco-plugin-log-craco-config");
module.exports = {
...
plugins: [
{ plugin: logCracoConfigPlugin, options: { preText: "Will log the craco config:" } }
]
};
The function overrideWebpackConfig
let a plugin override the webpack config object after it's been customized by craco
.
The function must return a valid config object, otherwise craco
will throw an error.
The function will be called with a single object argument having the following structure:
{
webpackConfig: "The webpack config object customized by craco",
cracoConfig: "The configuration object read from the craco.config.js file provided by the consumer",
pluginOptions: "The plugin options provided by the consumer",
context: {
env: "The current NODE_ENV (development, production, etc..)",
paths: "An object that contains all the paths used by CRA"
}
}
Plugin:
/* craco-plugin-log-webpack-config.js */
module.exports = {
overrideWebpackConfig: ({ webpackConfig, cracoConfig, pluginOptions, context: { env, paths } }) => {
if (pluginOptions.preText) {
console.log(pluginOptions.preText);
}
console.log(JSON.stringify(webpackConfig, null, 4));
// Always return the config object.
return webpackConfig;
}
};
Registration (in a craco.config.js
file):
const logWebpackConfigPlugin = require("./craco-plugin-log-webpack-config");
module.exports = {
...
plugins: [
{ plugin: logWebpackConfigPlugin, options: { preText: "Will log the webpack config:" } }
]
};
A few utility functions are provided by craco
to develop a plugin:
const { getLoader, getLoaders, removeLoader, loaderByName } = require("craco");
Retrieve the first loader that match the specified criteria from the webpack config.
Returns:
{
isFound: true | false,
match: {
loader,
parent,
index
}
}
Usage:
const { getLoader, loaderByName } = require("craco");
const { isFound, match } = getLoader(webpackConfig, loaderByName("eslint-loader"));
if (isFound) {
// do stuff...
}
Retrieve all the loaders that match the specified criteria from the webpack config.
Returns:
{
hasFoundAny: true | false,
matches: [
{
loader,
parent,
index
}
]
}
Usage:
const { getLoaders, loaderByName } = require("craco");
const { hasFoundAny, matches } = getLoaders(webpackConfig, loaderByName("babel-loader"));
if (hasFoundAny) {
matches.forEach(x => {
// do stuff...
});
}
Remove the first loader that match the specified criteria from the webpack config.
Usage:
const { removeLoader, loaderByName } = require("craco");
removeLoader(webpackConfig, loaderByName("eslint-loader"));
@timarney for having created react-app-rewired.
Copyright Š 2018, Groupe Sharegate inc. This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license at https://github.com/sharegate/craco/blob/master/LICENSE.
FAQs
Create React App Configuration Override, an easy and comprehensible configuration layer for create-react-app.
The npm package @craco/craco receives a total of 391,885 weekly downloads. As such, @craco/craco popularity was classified as popular.
We found that @craco/craco demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.