webpack 4
there is one common config:
const defaultConfig = { mode: 'development', cache: true, module: { rules: [...] } ..., plugins: [ new MiniCssExtractPlugin({ // Options similar to the same options in webpackOptions.output // both options are optional filename: '[name].css', chunkFilename: '[name].chunk.css', }) ], } And the entry point object:
const chunks = { common: require(path.join(PROJECT_ROOT, 'static/compilers/webpack/cores/common.config.js')), mobile: require(path.join(PROJECT_ROOT, 'static/compilers/webpack/cores/mobile.config.js')), admin: require(path.join(PROJECT_ROOT, 'static/compilers/webpack/cores/admin.config.js')), ... }; Further, all entry points "merge" with the main config:
const configs = []; Object.keys(chunks).forEach(key => { const config = { ...defaultConfig, ...chunks[key] }; configs.push(config); }); And everything is exported:
module.exports = configs; Each individual chunk has a similar structure:
/** common.config.js каждый конфиг имеет свою директорию common, mobile, admin в output.publicPath и path */ const PROJECT_ROOT = path.resolve(__dirname, '../../.././'); const COMPILE_DIR = path.join(PROJECT_ROOT, 'compile/default/js/'); module.exports = { entry: { пути к файлам }, output: { path: path.join(COMPILE_DIR, 'common'), publicPath: path.join(COMPILE_DIR, 'common'), filename: '[name].js', chunkFilename: '[name].chunk.js', sourceMapFilename: '[name].map.js' }, }; The problem is that the webpack does not keep track of changes to files specified in common.config.js, and with others, everything is fine.