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-scriptsin 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:
constgeneralConfig=require('react-scripts/config/webpack.config.dev');// Switch on css-modulesgeneralConfig.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 ezhlobo@gmail.com 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 (ezhlobo@gmail.com) 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.jsto do patches fordevandprodconfigs by the same way.
classPatcher{staticisCssLoader(handler){returnhandler.test.toString().indexOf('\\.css')>-1;}constructor(config){this.config=config;returnthis;}patchLoader(test,patch){this.config.module.loaders.forEach(handler=>{if(test(handler)){patch(handler);}})returnthis;}patchCssLoader(patch){returnthis.patchLoader(Patcher.isCssLoader,patch);}}module.exports=Patcher;- I patch
devconfig in./config/webpack.config.dev.js:
constPatcher=require('./patcher');constgeneralConfig=require('react-scripts/config/webpack.config.dev');module.exports=newPatcher(generalConfig).patchCssLoader(handler=>{handler.loader='style!css?module!postcss';}).config;- I patch
prodconfig in./config/webpack.config.prod.js:
constPatcher=require('./patcher');constgeneralConfig=require('react-scripts/config/webpack.config.prod');constExtractTextPlugin=require('extract-text-webpack-plugin');module.exports=newPatcher(generalConfig).patchCssLoader(handler=>{handler.loader=ExtractTextPlugin.extract('style','css?-autoprefixer&module!postcss');}).config;