arc-resolver v3.0.0
arc-resolver
API
new Resolver(fs)
import Resolver from 'arc-resolver';fs(optional): a filesystem that conforms to the node.jsfsapi. Defaults to the built-infsmodule
Instance methods
clearCache()getMatchesSync(path)getDirMatchesSync(dir, request)resolveSync(path, flags)isAdaptiveSync(path)
new MatchSet(matches) an iterable
import { MatchSet } from 'arc-resolver';matches(required): anArrayofObjects with the keysflagsandvalue:flags: anArrayof strings representing the required flags for thevaluevalue: any value to associate with theflags
Properties
count: the number of possible matchesdefault: the default value (the least specific, the one with no flags)
Methods
match(flags): return the matchingvaluefor a flagsetflags: anObjectwhere each key represents a flag and the value is a boolean indicating whether that flag is active
Defining flags
arc adapts files based on a filenaming convension:
style.css
style[android].cssHow it works
Write your application as though the flagged version of the file did not exist:
@import url('./style.css');When bundling the css (using arc-webpack or arc-lasso), if the android flag is set, style[android].css will replace style.css in the output bundle.
Multiple flags
Require all flags (AND)
Use the plus (+) to specify that all of the listed flags need to match:
style[mobile+android].cssRequire any flag (OR)
Use the comma (,) to specify that one of the listed flags needs to match:
style[android,ios].cssCombining flag logic
The plus (+) has higher precedence than the comma (,), similar to how && has higher precedence than || in JavaScript.
For example,
style[mobile+ios,mobile+android].cssIs logically equivalent to:
(mobile && ios) || (mobile && android)Subgroups of flags
To increase the precedence of a group, you can wrap it in []:
style[mobile+[ios,android]].cssThis is logically equivalent to the previous example.
Specificity
More Flags === Higher Specificity
Given the following files:
style.css
style[mobile,tablet,headset,desktop].css
style[mobile+[ios,android]].css
style[mobile+ios+chrome,safari].cssThe matching logic looks something like:
if mobile & ios & chrome
'style[mobile+ios+chrome,safari].css'
else if mobile & ios
'style[mobile+[ios,android]].css'
else if mobile & android
'style[mobile+[ios,android]].css'
else if safari
'style[mobile+ios+chrome,safari].css'
else if mobile
'style[mobile,tablet,headset,desktop].css'
else if tablet
'style[mobile,tablet,headset,desktop].css'
else if headset
'style[mobile,tablet,headset,desktop].css'
else if desktop
'style[mobile,tablet,headset,desktop].css'
else
'style.css'2 years ago
4 years ago
6 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago