A rollup plugin for analysing your JavaScript file and generating a https://polyfill.io (new url: https://cdnjs.cloudflare.com/polyfill) URL based on all the features that are being used from within the JavaScript file.
npm install --save-dev rollup-plugin-polyfill-serviceConfigure plugin for rollup:
import polyfill from "rollup-plugin-polyfill-service";
export default {
input: "entry.js",
output: { /* ... */ }
plugins: [
// ...
polyfill({
inject: "index.html"
})
]
}Add the following line to your index.html:
<script src="https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js"></script>When running rollup, rollup-plugin-polyfill-service will analyze the built bundle, generate a https://cdnjs.cloudflare.com/polyfill URL based on your needs and inject the URL in your index.html file.
polyfillUrl: The URL to the polyfill service to generate URL for. (default: https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js)include: One or more minimatch patterns. (default: *.js)exclude: One or more minimatch patterns.inject: One or more path to html files to inject URL in or an object to control injection:target: One or more path to html files to inject URL in.pattern: A string orRegExpto detect inject location. (default:${polyfillUrl}[^"' ]*)
browserslist: A browserslist query or an object to pass options to browserslist.query: A browserslist query....options: Any browserslist options.
print: Set totrueto print the generated URL in the console during build.
We use SemVer for versioning. For the versions available, see the tags on this repository.
This project is licensed under the MIT License - see the LICENSE file for details.