You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
5 years ago
|
"use strict";
|
||
|
|
||
|
const postcss = require("postcss");
|
||
|
const defaultValue = require("default-value");
|
||
|
const postcssValues = require("postcss-modules-values");
|
||
|
const postcssLocalByDefault = require("postcss-modules-local-by-default");
|
||
|
const postcssExtractImports = require("postcss-modules-extract-imports");
|
||
|
const postcssScope = require("postcss-modules-scope");
|
||
|
const genericNames = require("generic-names");
|
||
|
|
||
|
const postcssFindImports = require("./postcss-icss-find-imports");
|
||
|
|
||
|
module.exports = function createFilePreprocessor(options) {
|
||
|
let generateScopedName = defaultValue(options.generateScopedName, genericNames("[name]__[local]---[hash:base64:5]"));
|
||
|
|
||
|
let postcssInstance = postcss([
|
||
|
... defaultValue(options.before, []),
|
||
|
postcssValues,
|
||
|
postcssLocalByDefault({ mode: defaultValue(options.mode, "local") }),
|
||
|
postcssExtractImports(),
|
||
|
postcssScope({
|
||
|
generateScopedName: generateScopedName
|
||
|
}),
|
||
|
postcssFindImports()
|
||
|
]);
|
||
|
|
||
|
return function preprocessFile(item) {
|
||
|
return postcssInstance.process(item.source, {
|
||
|
from: item.file,
|
||
|
... options
|
||
|
});
|
||
|
};
|
||
|
};
|