Analyse your JavaScript file and generate a polyfill.io URL based on all the features that are being used from within the JavaScript file.
npm install @qiwi/create-polyfill-service-url``bash`
> npx create-polyfill-service-url analyse --file bundle.js [--cwd "/custom/pwd" --omit "Array.prototype.includes" --hostname "polyfill.io"]`
You can pass multiple files as argument if you split your bundle files:bash`
npx create-polyfill-service-url analyse --file app.js vendor.js
| Option | Description | Default |
|-------------------------------|-------------------------------------------------------------------------------------------------------------|-----------------|
| --file | The path to the JavaScript file(s) to analyse | |
| --cwd | The current working directory | process.cwd() |Array.prototype.map
| --omit | A list of features to omit. Example: | |polyfill.io
| --hostname | The hostname of the polyfill service to use. | |yes
| --use-compute-at-edge-backend | Defines the compute-at-edge-backend usage policy: or no. If empty the server will decide. | |always
| --flags | Configuration settings for every polyfill being requested. Possible values are and gated or both | |polyfill
| --unknown | Defines the policy for unsupported browsers: or ignore | polyfill |
js
const analyze = require('create-polyfill-service-url');const result = await analyze({
file: ['bundle.js'],
cwd: '/foo/bar', // Defaults to process.cwd()
omit: ['Array.prototype.includes'], // Defaults to []
hostname: 'example.com', // Defaults to 'polyfill.io'
unknown: 'polyfill', // Defaults to null. Accepts 'polyfill' or 'ignore'
useComputeAtEdgeBackend: 'yes', // Defaults to null. Accepts 'yes' or 'no'
flags: 'gated', // Defaults to null. Accepts 'always', 'gated' or both ['always', 'gated']
});
`Diff
* introduce omit option to suppress false-positive matches in case some custom polyfill is already present in the bundle or provided another way.
* add cwd option to avoid cd (monorepo build case)
* provide hostname customization
* introduce flags, useComputeAtEdgeBackend and unknown options
* expose analyse` JS APIThis project is licensed under the MIT License - see the LICENSE.md file for details
[issues]: https://github.com/Financial-Times/polyfill-service-url-builder/issues
[node.js]: https://nodejs.org/
[npm]: https://www.npmjs.com/