-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.ts
More file actions
50 lines (44 loc) · 1.1 KB
/
mod.ts
File metadata and controls
50 lines (44 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import {
applyDirective,
applyExtractor,
Config,
fromFileSystem,
generate,
MapCSSOption,
mergeConfig,
PluginCreator,
resolveConfigFile,
resolveConfigFilePath,
} from "./deps.ts";
export type Option = Readonly<
& Config
& MapCSSOption
& Partial<{
/** Whether load MapCSS config file or not.
* @default true
*/
useConfig: boolean;
}>
>;
const mapcss: PluginCreator<Option> = (option) => {
return {
postcssPlugin: "postcss-mapcss",
Once: async (root) => {
const { injectCSS, ...rest } = option ?? {};
let _config: Config | undefined;
if (option?.useConfig ?? true) {
const path = await resolveConfigFilePath(fromFileSystem());
if (path) {
_config = await resolveConfigFile(path);
}
}
const config = mergeConfig(_config ?? {}, rest ?? {});
await applyDirective(root, (input) => {
const tokens = applyExtractor(input, config?.extractor);
return generate(tokens, config ?? {}, { injectCSS: injectCSS ?? true });
});
},
};
};
mapcss.postcss = true;
export default mapcss;