Question
When exporting a bundle in Webpack, how can I exclude 3rd-party module's peerDependency? (not 3rd-party module itself)
Background
I would like to create an UIkit with customized components on top of angular-material
framework. With Webpack, I can bundle my customzied components and angular-material together into something like uikit.js
, and then port to other application later on. However, I don't want to include angular
module itself into this uikit.js
.
Issue
It seems that Webpack is "clever" enough to notice that angular
module is a dependency of angular-material
module, and thus would export both angular
module and angular-material
module to the bundle. One can either use config.externals: {'angular': 'angular'}
or new webpack.IgnorePlugin(/angular$/)
to exclude angular
module which are explicitly require in the app, but for peerDependency (i.e. the one require inside angular-material
), it would still include it.
So, how could I exclude this 3rd-party depended modules out from export?
Example:
// app.js
var angular = require('angular');
var material = require('angular-material');
// ... other application logic
// webpack.config.js
var webpack = require('webpack');
module.exports = {
entry: {
app: './app.js'
},
module: {
loaders: [
// some module loaders
]
},
// This only excludes the angular module require by the app, not the one require by the angular-material
externals: {'angular': 'angular'},
plugins: [
// This is the same as externals, only the one required by app.js would be excluded
new webpack.IgnorePlugin(/angular$/)
]
};