Let's add a source map to our Webpack:
- Create the webpack/configuration/devtool.js file:
const isProduction = process.env.NODE_ENV === 'production';
export default !isProduction ? 'cheap-module-source-map' : 'eval';
File: webpack/configuration/devtool.js
- Split the bundles (using the new "optimization" Webpack node): one for our /node_modules/ which will be the biggest one, and one for our React Application. You need to create the optimization.js file and add this code:
export default {
splitChunks: {
cacheGroups: {
default: false,
commons: {
test: /node_modules/,
name: 'vendor',
chunks: 'all'
}
}
}
}
File: webpack/configuration/optimization.js
- Remember that you need to add those new files into index.js:
// Configuration
import devtool from './devtool';
import module from './module';
import optimization from './optimization';
import plugins from './plugins';
import resolve from './resolve';
export {
devtool,
module,
optimization,
plugins,
resolve
};
File: webpack/configuration/index.js
- Add the nodes to webpack.config.babel.js:
import {
devtool,
module,
optimization,
plugins,
resolve
} from './webpack/configuration';
export default {
devtool,
module,
plugins,
optimization,
resolve
};
File: webpack.config.babel.js