Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions plugin-packs/postcss-preset-env/.tape.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,16 @@ postcssTape(plugin)({
}
},
'disable-client-side-polyfills': {
message: 'supports { disableClientSidePolyfills: true } usage',
message: 'supports { enableClientSidePolyfills: false } usage',
options: {
disableClientSidePolyfills: true,
enableClientSidePolyfills: false,
stage: 0,
}
},
'disable-client-side-polyfills:disabled': {
message: 'supports { disableClientSidePolyfills: false } usage (default)',
message: 'supports { enableClientSidePolyfills: true } usage (default)',
options: {
disableClientSidePolyfills: false,
enableClientSidePolyfills: true,
stage: 0,
}
},
Expand Down
6 changes: 3 additions & 3 deletions plugin-packs/postcss-preset-env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ to the polyfill's library.
* `has-pseudo-class`: [Plugin](https://github.com/csstools/postcss-plugins/blob/main/plugins/css-has-pseudo) / [Polyfill](https://github.com/csstools/postcss-plugins/blob/main/plugins/css-has-pseudo/README-BROWSER.md)
* `prefers-color-scheme-query`: [Plugin](https://github.com/csstools/postcss-plugins/blob/main/plugins/css-prefers-color-scheme) / [Polyfill](https://github.com/csstools/postcss-plugins/blob/main/plugins/css-prefers-color-scheme/README-BROWSER.md)

If you want to disable these types of features, please check the [`disableClientSidePolyfills` option](#disableclientsidepolyfills).
If you want to disable these types of features, please check the [`enableClientSidePolyfills` option](#enableclientsidepolyfills).

## Usage

Expand Down Expand Up @@ -407,9 +407,9 @@ postcssPresetEnv({

The `debug` option enables debugging messages to stdout which should be useful to help you debug which features have been enabled/disabled and why.

### disableClientSidePolyfills
### enableClientSidePolyfills

The `disableClientSidePolyfills` disables any feature that would need an extra browser library to be loaded into the page for it to work.
The `enableClientSidePolyfills` enables any feature that would need an extra browser library to be loaded into the page for it to work. Defaults to `true`.

Note that manually enabling/disabling features via the "feature" option overrides this flag.

Expand Down
6 changes: 3 additions & 3 deletions plugin-packs/postcss-preset-env/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const plugin = opts => {
// initialize options
const options = Object(opts);
const features = Object(options.features);
const disableClientSidePolyfills = options.disableClientSidePolyfills;
const enableClientSidePolyfills = 'enableClientSidePolyfills' in options ? options.enableClientSidePolyfills : true;
const featureNamesInOptions = Object.keys(features);
const insertBefore = Object(options.insertBefore);
const insertAfter = Object(options.insertAfter);
Expand Down Expand Up @@ -84,7 +84,7 @@ const plugin = opts => {
// staged features (those at or above the selected stage)
const stagedFeatures = polyfillableFeatures.filter(feature => {
const isAllowedStage = feature.stage >= stage;
const isAllowedByType = !disableClientSidePolyfills || !featuresWithClientSide.includes(feature.id);
const isAllowedByType = enableClientSidePolyfills || !featuresWithClientSide.includes(feature.id);
const isDisabled = features[feature.id] === false;
const isAllowedFeature = features[feature.id] ? features[feature.id] : isAllowedStage && isAllowedByType;

Expand All @@ -97,7 +97,7 @@ const plugin = opts => {
log(` ${feature.id} with stage ${feature.stage} has been disabled`);
}
} else if (!isAllowedByType) {
log(` ${feature.id} has been disabled by "disableClientSidePolyfills".`);
log(` ${feature.id} has been disabled by "enableClientSidePolyfills: false".`);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After switching this line became a bit weird :
has been disabled by "enableClientSidePolyfills"

so I added the : false bit.

}

return isAllowedFeature;
Expand Down