Some context:
I have been told by coworkers that the new version of Webpack handles the configuration in different files: webpack.development.config.js, webpack.production.config.js... (and you can even create custom modes). But they didn't know how the explain the whole thing. Only that now everything is done with multiple config files.
From the official docs, I see that the different modes have a comment on the top stating different file names:
Development
// webpack.development.config.js
module.exports = {
mode: 'development',
};
Production
// webpack.production.config.js
module.exports = {
mode: 'production',
};
So there must be some truth in this and I want to follow best practices. It seems logic that keeping config for different modes separate is a good thing to do.
But I don't know how I should correctly load plugins now.
I used to have this at the top of my files:
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const WatchTimePlugin = require('webpack-watch-time-plugin');
const cssnano = require('cssnano');
const autoprefixer = require('autoprefixer');
const webpack = require('webpack');
So, this ends up leaving me with the following questions.
Questions
Do I still need a global config file for Webpack? If there isn't any global config file, how can I have common tasks that I want to run both for production and development?
Does webpack load all files called webpack.xxxxxx.config.js? Can I just create whatever config files I like with that name and it will take them all into consideration?
How can I achieve common config for dev and prod, and then special extended config for dev and prod?
I find that the documentation isn't really clear about all this. So any help will be appreciated.