Skip to content

Add env option to control setting the browserslist environment #1012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 10, 2023
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
23 changes: 18 additions & 5 deletions cli/csstools-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,20 @@ Options:
-p, --plugin-options Stringified JSON object with plugin options

Plugin Options:
stage number
features object
browsers string
autoprefixer object
preserve boolean
stage number
minimumVendorImplementations number
features object
env string
browsers string
autoprefixer object
preserve boolean
logical object
enableClientSidePolyfills boolean
debug boolean

{
"stage": 0,
"minimumVendorImplementations": 2,
"features": {
"blank-pseudo-class": {
"preserve": false
Expand All @@ -127,11 +133,18 @@ Plugin Options:
"preserve": true
}
},
"env": "production",
"browsers": "last 2 versions",
"autoprefixer": {
"grid": true
},
"preserve": false,
"logical": {
"inlineDirection": "left-to-right",
"blockDirection": "top-to-bottom"
},
"enableClientSidePolyfills": false,
"debug": false
}
```

Expand Down
2 changes: 1 addition & 1 deletion cli/csstools-cli/dist/cli.cjs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions cli/csstools-cli/src/plugins/postcss-preset-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default function postcssPresetEnv() {
'stage',
'minimumVendorImplementations',
'features',
'env',
'browsers',
'autoprefixer',
'preserve',
Expand All @@ -26,6 +27,7 @@ export default function postcssPresetEnv() {
'blank-pseudo-class': { preserve: false },
'color-functional-notation': { preserve: true },
},
env: 'production',
browsers: 'last 2 versions',
autoprefixer: { grid: true },
preserve: false,
Expand Down
7 changes: 6 additions & 1 deletion e2e/browserslist/package-json/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import assert from 'assert';
import plugin from 'postcss-preset-env';
import postcss from 'postcss';

const result = (await postcss([plugin()]).process(':any-link { color: blue; }')).css;
const result = (await postcss([plugin()]).process(
':any-link { color: blue; }',
{from: undefined},
)).css;

assert.ok(['production', 'development'].includes(process.env.BROWSERSLIST_ENV));

if (process.env.BROWSERSLIST_ENV === 'production') {
assert.equal(
Expand Down
4 changes: 2 additions & 2 deletions e2e/browserslist/package-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"private": true,
"description": "Can you use PostCSS Preset Env with a browserslist in package.json?",
"scripts": {
"test": "BROWSERSLIST_ENV=development node ./index.mjs && BROWSERSLIST_ENV=production node ./index.mjs"
"test": "BROWSERSLIST_ENV=development node ./index.mjs && BROWSERSLIST_ENV=production node ./index.mjs && node ./use-plugin-option.mjs"
},
"devDependencies": {
"postcss": "^8.4.25",
"postcss-preset-env": "^9.0.0"
"postcss-preset-env": "file:../../../plugin-packs/postcss-preset-env"
},
"browserslist": {
"development": [
Expand Down
23 changes: 23 additions & 0 deletions e2e/browserslist/package-json/use-plugin-option.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import assert from 'assert';
import plugin from 'postcss-preset-env';
import postcss from 'postcss';

const resultProduction = (await postcss([plugin({env: 'production'})]).process(
':any-link { color: blue; }',
{from: undefined},
)).css;

const resultDevelopment = (await postcss([plugin({env: 'development'})]).process(
':any-link { color: blue; }',
{from: undefined},
)).css;

assert.equal(
resultProduction,
':link, :visited, area[href] { color: blue; }\n' +
':-webkit-any-link { color: blue; }\n' +
':-moz-any-link { color: blue; }\n' +
':any-link { color: blue; }',
);

assert.equal(resultDevelopment, ':any-link { color: blue; }');
Loading