You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43-2Lines changed: 43 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,7 @@ An extremely fast CSS parser, transformer, and minifier written in Rust. Use it
23
23
- Removing default property sub-values which will be inferred by browsers.
24
24
- Many micro-optimizations, e.g. converting to shorter units, removing unnecessary quotation marks, etc.
25
25
-**Vendor prefixing** – Lightning CSS accepts a list of browser targets, and automatically adds (and removes) vendor prefixes.
26
+
-**Browserslist configuration** – Lightning CSS supports opt-in browserslist configuration discovery to resolve browser targets and integrate with your existing tools and config setup.
26
27
-**Syntax lowering** – Lightning CSS parses modern CSS syntax, and generates more compatible output where needed, based on browser targets.
27
28
- CSS Nesting (draft spec)
28
29
- Custom media queries (draft spec)
@@ -197,6 +198,46 @@ To see all of the available options, use the `--help` argument:
197
198
npx lightningcss --help
198
199
```
199
200
201
+
#### Browserslist configuration
202
+
203
+
If the `--browserslist` option is provided, then `lightningcss` finds browserslist configuration,
204
+
selects queries by environment and loads the resulting queries as targets.
205
+
206
+
Configuration discovery and targets resolution is modeled after the original `browserslist` nodeJS package.
207
+
The configuration is resolved in the following order:
208
+
209
+
- If a `BROWSERSLIST` environment variable is present, then load targets from its value. This is analog to the `--targets` CLI option.
- If none of the above apply, then find, parse and use targets from the first `browserslist`, `.browserslistrc`
215
+
or `package.json` configuration file in any parent directory.
216
+
217
+
Browserslist configuration files may contain sections denoted by angular brackets `[]`.
218
+
Use these to specify different targets for different environments.
219
+
Targets which are not placed in a section are added to `defaults` and used if no section applies matches the environment.
220
+
221
+
_Example:_
222
+
223
+
```
224
+
# Defaults, applied when no other section matches the provided environment.
225
+
firefox ESR
226
+
227
+
[staging]
228
+
# Targets applied only to the staging environment.
229
+
samsung >= 4
230
+
```
231
+
232
+
When using parsed configuration from `browserslist`, `.browserslistrc` or `package.json` configuration files,
233
+
the environment determined by
234
+
235
+
- the `BROWSERSLIST_ENV` environment variable if present,
236
+
- otherwise the `NODE_ENV` environment variable if present,
237
+
- otherwise `production` is used.
238
+
239
+
If no targets are found for the resulting environment, then the `defaults` configuration section is used.
240
+
200
241
### Error recovery
201
242
202
243
By default, Lightning CSS is strict, and will error when parsing an invalid rule or declaration. However, sometimes you may encounter a third party library that you can't easily modify, which unintentionally contains invalid syntax, or IE-specific hacks. In these cases, you can enable the `errorRecovery` option (or `--error-recovery` CLI flag). This will skip over invalid rules and declarations, omitting them in the output, and producing a warning instead of an error. You should also open an issue or PR to fix the issue in the library if possible.
@@ -207,7 +248,7 @@ By default, Lightning CSS is strict, and will error when parsing an invalid rule
207
248
<imgwidth="680"alt="performance and build size charts"src="https://user-images.githubusercontent.com/19409/189022693-6956b044-422b-4f56-9628-d59c6f791095.png#gh-dark-mode-only">
0 commit comments