CSS Module Loader Core
A loader-agnostic CSS Modules implementation, based on PostCSS
API
let core =
Promise({ injectableSource, exportTokens })
core.load( sourceString , sourcePath , pathFetcher ) =>Processes the input CSS sourceString
, looking for dependencies such as @import
or :import
. Any localisation will happen by prefixing a sanitised version of sourcePath
When dependencies are found, it will ask the pathFetcher
for each dependency, resolve & inline any imports, and return the following object:
injectableSource
: the final, merged CSS file without@import
or:import
statementsexportTokens
: the mapping from local name to scoped name, as described in the file's:export
block
These should map nicely to what your build-tool-specific loader needs to do its job.
new Core([plugins])
The default set of plugins is [postcss-modules-local-by-default, postcss-modules-extract-imports, postcss-modules-scope] (i.e. the CSS Modules specification). This can override which PostCSS plugins you wish to execute, e.g.
// Don't run local-by-default, but use colorFunctions // beforehand and autoprefixer afterwards:let core = colorFunctions corepluginsextractImports corepluginsscope