The core functionality of modular-css
exposed as a JS API.
Install
$ npm i modular-css-core
Usage
Instantiate a new Processor
instance, call it's .file(<path>)
or .string(<name>, <contents>)
methods, and then use the returned Promise to get access to the results/output.
var Processor = processor = // See "API Options" for valid options to pass to the Processor constructor ; // Add entries, either from disk using .file() or as strings with .string()Promiseall processor processor;
Processor Options
before
Specify an array of PostCSS plugins to be run against each file before it is processed.
before : ;
after
Specify an array of PostCSS plugins to be run after files are processed, but before they are combined. Plugin will be passed a to
and from
option.
By default postcss-url
is used in after
mode.
after : ;
done
Specify an array of PostCSS plugins to be run against the complete combined CSS.
done : ;
map
Enable source map generation. Can also be passed to .output()
.
Default: false
map : true;
cwd
Specify the current working directory for this Processor instance, used when resolving composes
/@value
rules that reference other files.
Default: process.cwd()
cwd : path
namer
Specify a function (that takes filename
& selector
as arguments to produce scoped selectors.
Default: Function that returns "mc" + unique-slug(<file>) + "_" + selector
{ return file + "_" + selector; };
resolvers
If you want to provide your own file resolution logic you can pass an array of resolver functions. Each resolver function receives three arguments:
src
, the file that includedfile
file, the file path being included by
src`resolve
, the default resolver function
Resolver functions should either return an absolute path or a falsey value. They must also be synchronous.
Default: See /src/lib/resolve.js for the default implementation.
resolvers : ... "./some/other/path"
exportGlobals
Enable exporting :global
identifiers.
Default: true
exportDefaults: false
/* exportGlobals: true */) /* Outputs{ "a" : "mc12345_a", "b" : "b"}*/ /* exportGlobals: false */) /* Outputs{ "a" : "mc12345_a"}*/