Skip to content

Commit e7e51a4

Browse files
committed
added a README with API ideas
1 parent f893770 commit e7e51a4

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# CSS Module Loader Core
2+
> A loader-agnostic CSS Modules implementation, based on PostCSS
3+
4+
## API
5+
6+
### core.load( sourceString , pathFetcher ) => { injectableSource, exportTokens }
7+
8+
Processes the input CSS `sourceString`, looking for dependencies such as `@import` or `:import`. When dependencies are found, it will ask the `pathFetcher` for each dependency, resolve & inline any imports, and return the following object:
9+
10+
- `injectableSource`: the final, merged CSS file without `@import` or `:import` statements
11+
- `exportTokens`: the mapping from local name to scoped name, as described in the file's `:export` block
12+
13+
These should map nicely to what your build-tool-specific loader needs to do its job.
14+
15+
### core.plugins = pluginArray
16+
17+
The default set of plugins is [[postcss-modules-local-by-default](https://github.com/css-modules/postcss-modules-local-by-default), [postcss-modules-extract-imports](https://github.com/css-modules/postcss-modules-extract-imports), [postcss-modules-scope](https://github.com/css-modules/postcss-modules-scope)] (i.e. the CSS Modules specification). This can override which PostCSS plugins you wish to execute, e.g.
18+
19+
```js
20+
import core from 'css-loader-core'
21+
import autoprefixer from 'autoprefixer'
22+
import colorFunctions from 'postcss-color-function'
23+
24+
// Don't run local-by-default, but use colorFunctions
25+
// beforehand and autoprefixer afterwards:
26+
core.plugins = [
27+
colorFunctions,
28+
core.plugins.extractImports,
29+
core.plugins.scope,
30+
autoprefixer("Last 2 Versions")
31+
]
32+
```
33+

0 commit comments

Comments
 (0)