Last active
June 27, 2017 20:28
-
-
Save akrawchyk/387febf84a16dfd04c608e39c21c83b4 to your computer and use it in GitHub Desktop.
Webpack vendor and modules example
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
var webpack = require('webpack'); | |
var path = require('path'); | |
module.exports = function(env) { | |
return { | |
entry: { | |
// main pages JS | |
page1: './page1/index.js', | |
page2: './page2/index.js', | |
// selectively loaded JS | |
mySelect2: './components/mySelect2.js', | |
myCropit: './components/myCropit.js' | |
}, | |
output: { | |
filename: '[name].[chunkhash].js', | |
path: path.resolve(__dirname, 'dist') | |
}, | |
plugins: [ | |
new webpack.optimize.CommonsChunkPlugin({ | |
name: 'common' | |
}), | |
new webpack.optimize.CommonsChunkPlugin({ | |
name: 'vendor', | |
minChunks: function (module) { | |
// explicit exclude from vendor (included instead in component files) | |
if (/node_modules\/cropit/.test(module.resource)) { | |
return false | |
} | |
if (/node_modules\/select2/.test(module.resource)) { | |
return false | |
} | |
// include everything else in vendor | |
return /node_modules/.test(module.resource) | |
} | |
}), | |
new webpack.optimize.CommonsChunkPlugin({ | |
name: 'manifest' | |
}) | |
] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment