afl
autopolyfiller-fxd-loader
npm i autopolyfiller-fxd-loader
afl

autopolyfiller-fxd-loader

🏭 Autopolyfiller loader for webpack

by Kir Belevich

0.4.1 (see all)License:WTFPLTypeScript:Not Found
npm i autopolyfiller-fxd-loader
Readme

Autopolyfiller loader for webpack

npm travis climate deps gratipay

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' ], //list of browsers to polyfill
          withParser: ['acorn@0.11.0', {ecmaVersion: 6}], //allow use custom parser
          exclude: ['Promise'], //exclude some polyfills
          include: ['Object.create'], //force include some polifills
          use: [{
                    // AST tree pattern matching
                    // It may "grep" multiply polyfills
                    test: function (ast) {
                        return query('Object.newFeature(_$)', ast).length > 0 ? ['Object.newFeature'] : [];
                    },

                    // Your polyfills code
                    polyfill: {
                        'Object.newFeature': 'Object.newFeature = function () {};'
                    },

                    // This list means "apply this feature to the <list of browsers>"
                    // For more examples see https://github.com/jonathantneal/polyfill/blob/master/agent.js.json
                    support: {
                        // For chrome 29 only apply Object.newFeature polyfill
                        'Chrome': [{
                            only: '29',
                            fill: 'Object.newFeature'
                        }]
                    },

                    // This is optional. By default autopolyfiller will use
                    // polyfill's name to generate condition's code:
                    wrapper: {
                        'Object.newFeature': {
                            'before': 'if (!("newFeature" in Object)) {',
                            'after': '}'
                        }
                    }
                }] //add custom polyfills
        }
    } ]
}

Documentation: Using loaders.

License

WTFPL

Downloads/wk

4

GitHub Stars

68

LAST COMMIT

5yrs ago

MAINTAINERS

1

CONTRIBUTORS

6

OPEN ISSUES

2

OPEN PRs

0
VersionTagPublished
0.4.1
latest
6yrs ago
No alternatives found
No tutorials found
Add a tutorial