Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let cssText = '';
let preprocessor;
if (typeof options.preprocessor === 'function') {
// eslint-disable-next-line prefer-destructuring
preprocessor = options.preprocessor;
} else {
switch (options.preprocessor) {
case 'none':
preprocessor = (selector, text) => `${selector} {${text}}\n`;
break;
case 'stylis':
default:
stylis.use(null)((context, decl) => {
if (context === STYLIS_DECLARATION && options.outputFilename) {
// When writing to a file, we need to adjust the relative paths inside url(..) expressions
// It'll allow css-loader to resolve an imported asset properly
return decl.replace(
/\b(url\()(\.[^)]+)(\))/g,
(match, p1, p2, p3) =>
p1 +
// Replace asset path with new path relative to the output CSS
path.relative(
/* $FlowFixMe */
path.dirname(options.outputFilename),
// Get the absolute path to the asset from the path relative to the JS file
path.resolve(path.dirname(options.filename), p2)
) +
p3
);
parse: code => {
stylis.use(null);
return {css: stylis('', code), tokens: {}};
},
});