
This is like Autoprefixer, but for JavaScript polyfills. It scans your code and applies only required polyfills.
Install
$ npm i -S autopolyfiller-loader
Usage
module: {
postLoaders: [ {
test: /\.js$/,
exclude: /\/(node_modules|bower_components)\//,
loader: 'autopolyfiller',
query: {
browsers: [ 'last 2 versions', 'ie >= 9' ],
withParser: ['acorn@0.11.0', {ecmaVersion: 6}],
parserOptions: {ecmaVersion: 6},
exclude: ['Promise'],
include: ['Object.create'],
use: [{
test: function (ast) {
return query('Object.newFeature(_$)', ast).length > 0 ? ['Object.newFeature'] : [];
},
polyfill: {
'Object.newFeature': 'Object.newFeature = function () {};'
},
support: {
'Chrome': [{
only: '29',
fill: 'Object.newFeature'
}]
},
wrapper: {
'Object.newFeature': {
'before': 'if (!("newFeature" in Object)) {',
'after': '}'
}
}
}]
}
} ]
}
Documentation: Using loaders.
License
WTFPL