Merge webpack alias configuration in one single file
Created by: Spyna
There are two webpack configuration files, one is for development
and the other for production
. Some parts of these files are duplicated, the alias
configuration is one of them.
This duplicated alias
configuration could be extracted to one external file and imported into the other two. In order to make its modification easier and faster.
webpack files involved:
- development:
packages/react-scripts/config/webpack.config.dev.js
https://github.com/facebook/create-react-app/blob/next/packages/react-scripts/config/webpack.config.dev.js - production:
packages/react-scripts/config/webpack.config.prod.js
https://github.com/facebook/create-react-app/blob/next/packages/react-scripts/config/webpack.config.prod.js
The only downside I can see is when you need to use different aliases for the two environments, but:
- this is a rare scenario
- if you need this differentiation, you probably are an expert and know how to manage this.
I suggest
...
const aliases = require('./webpack.alias.config');
...
resolve: {
...
alias: aliases
...
}
...