Get Dependencies
You can read package.json from babel-polyfill
const path = require('path'); function getDependencies () { // Read dependencies... const { dependencies } = require('node_modules/babel-polyfill/package.json'); // Extract module name return Object.keys(dependencies); }
Just call it (you need to return the array using dependencies ):
const dependencies = getDependencies();
Polynomial Detection
Check for babel-polyfill or dependency:
function isPolyfill(module){ // Get module name from path const name = path.posix.basename(module.context) // If module has a path return name && // If is main module or dependency ( name === "babel-polyfill" || dependencies.indexOf(name) !== -1 ); }
To remove babel-polyfill and dependencies, just check if false returned
new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', minChunks: function (module) { // If has path return module.context && //If is a node-module module.context.indexOf('node_modules')!== -1 && // Remove babel-polyfill and dependencies isPolyfill(module) === false; } })
Create a block of polylines
To select only babel-polyfill and dependencies just check if true returned
new webpack.optimize.CommonsChunkPlugin({ name: 'polyfills', minChunks: function (module) { // If has a path return module.context && //If is a node-module module.context.indexOf('node_modules')!== -1 && // Select only babel-polyfill and dependencies isPolyfill(module) === true; } })
source share