Created
September 2, 2017 19:12
-
-
Save chrisalexander55/93580aeca84dae22c2928371d4c141d9 to your computer and use it in GitHub Desktop.
dev.common.config.js - Webpack Subdirectory Bundle Injection Silently Fails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const Webpack = require('webpack'); | |
// webpack plugins | |
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin'); | |
module.exports = { | |
entry: { | |
'js/vendor': './src/app/js/vendor.js', | |
'index': './src/app/js/index/bootstrap.js', | |
'pages/some-page-1': './src/app/js/some-page-1/bootstrap.js', | |
'pages/some-page-2': './src/app/js/some-page-2/bootstrap.js' | |
}, | |
resolve: { | |
extensions: ['.js', '.scss'], | |
modules: ['node_modules'] | |
}, | |
module: { | |
rules: [ | |
{ | |
enforce: "pre", | |
test: /src\/app\/\.js$/, | |
exclude: /node_modules/, | |
loader: "eslint-loader", | |
options: { | |
outputReport: { | |
filePath: '../../es-style/es-style-errors.xml' | |
} | |
} | |
}, | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
loader: "babel-loader", | |
}, | |
{ | |
test: /\.json$/, | |
loader: 'json' | |
}, | |
{ | |
test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)$/, | |
loader: 'file', | |
} | |
] | |
}, | |
plugins: [ | |
new Webpack.NamedModulesPlugin(), | |
new Webpack.NamedChunksPlugin((chunk) => { | |
if (chunk.name) { | |
return chunk.name; | |
} | |
return chunk.modules.map(m => path.relative(m.context, m.request)).join("_"); | |
}), | |
// Put modules common to all modules into a separate chunk! | |
new Webpack.optimize.CommonsChunkPlugin({ | |
names: ["common", "vendor"], | |
name: 'common', | |
filename: 'js/common.js', | |
minChunks: 3 | |
}), | |
// Put common async (lazy) modules into a separate chunk! | |
new Webpack.optimize.CommonsChunkPlugin({ | |
async: "js/common-lazy.js", | |
children: true, | |
minChunks: 2 | |
}) | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment