
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@greenwood/plugin-polyfills
Advanced tools
A Greenwood plugin adding support for Web Component related polyfills like Custom Elements and Shadow DOM.
A Greenwood plugin adding support for Web Component related polyfills for browsers that need support for part of the Web Component spec like Custom Elements and Shadow DOM. It uses feature detection to determine what polyfills are actually needed based on the user's browser, to ensure only the minimum extra code is loaded. If you are using Lit@2, it also loads the needed polyfill-support.js file.
As of right now, you will likely need this plugin to load additional polyfills if you want to support these browser(s):
For more information and complete docs on Greenwood, please visit our website.
This package assumes you already have
@greenwood/cliinstalled.
You can use your favorite JavaScript package manager to install this package. This package assumes you already have @greenwood/cli installed.
# npm
$ npm i -D @greenwood/plugin-polyfills
# yarn
$ yarn add @greenwood/plugin-polyfills --dev
# pnpm
$ pnpm add -D @greenwood/plugin-polyfills
Use this plugin in your greenwood.config.js:
import { greenwoodPluginPolyfills } from '@greenwood/plugin-polyfills';
export default {
// ...
plugins: [
greenwoodPluginPolyfills()
]
}
Now when your project builds for production, you will see a bundles/ directory in your output directory, as well as a file called webcomponents-loader.js, as well as a <script> tag for that file in the <head> of your index.html files. When a page is loaded, the feature detection capabilities will then load the necessary polyfills to have your project work for a user's given browser.
Note: we would like to add support for differential loading to avoid the cost of this for newer browsers.
Types should automatically be inferred through this package's exports map, but can be referenced explicitly in both JavaScript (JSDoc) and TypeScript files if needed.
/** @type {import('@greenwood/plugin-polyfills').PolyfillsPlugin} */
import type { PolyfillsPlugin } from '@greenwood/plugin-polyfills';
This plugin supports the following polyfills and configuration options:
wcdsdlit (Use this in conjunction with Web Components Loader)You can adjust either of these default behaviors by providing true or false for each polyfill type.
import { greenwoodPluginPolyfills } from '@greenwood/plugin-polyfills';
export default {
// ...
// default values shown here
plugins: [
greenwoodPluginPolyfills({
wc: true,
dsd: false,
lit: false
})
]
}
FAQs
A Greenwood plugin adding support for Web Component related polyfills like Custom Elements and Shadow DOM.
We found that @greenwood/plugin-polyfills demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.