This package includes scripts and configuration used by Create React App.
I added the possibility of patching webpack configs. So you can switch on css-modules or add sass-loader if you want.
-
Set version of
react-scripts
in your package.json tohttps://github.com/ezhlobo/react-scripts.git#use-custom-config
. -
Run
npm update react-scripts
. -
Update scripts in package.json:
"scripts": {
"start": "WEBPACK_CONFIG_PATH=./config/webpack.config.dev.js react-scripts start",
"build": "WEBPACK_CONFIG_PATH=./config/webpack.config.prod.js react-scripts build",
- Create your config files in
./config
. Here's an example how to do patches:
const generalConfig = require('react-scripts/config/webpack.config.dev');
// Switch on css-modules
generalConfig.module.loaders[1].loader = 'style!css?module!postcss';
module.exports = generalConfig;
Take a look at default configs here: ezhlobo/react-scripts/tree/use-custom-config/config.
It's an advanced guide. Feel free to ask about it by sending an email to [email protected] or by creating an issue.
This fork will be updated when original react-scripts will be changed. I'll do it manually for now so we can get a delay. Feel free to email me ([email protected]) or create an issue. I'll respond in two days.
I want to provide an example how I use this fork for my projects.
- Firstly I created
./config/patcher.js
to do patches fordev
andprod
configs by the same way.
class Patcher {
static isCssLoader(handler) {
return handler.test.toString().indexOf('\\.css') > -1;
}
constructor(config) {
this.config = config;
return this;
}
patchLoader(test, patch) {
this.config.module.loaders.forEach(handler => {
if (test(handler)) {
patch(handler);
}
})
return this;
}
patchCssLoader(patch) {
return this.patchLoader(Patcher.isCssLoader, patch);
}
}
module.exports = Patcher;
- I patch
dev
config in./config/webpack.config.dev.js
:
const Patcher = require('./patcher');
const generalConfig = require('react-scripts/config/webpack.config.dev');
module.exports = new Patcher(generalConfig)
.patchCssLoader(handler => {
handler.loader = 'style!css?module!postcss';
})
.config;
- I patch
prod
config in./config/webpack.config.prod.js
:
const Patcher = require('./patcher');
const generalConfig = require('react-scripts/config/webpack.config.prod');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = new Patcher(generalConfig)
.patchCssLoader(handler => {
handler.loader = ExtractTextPlugin.extract('style', 'css?-autoprefixer&module!postcss');
})
.config;