From 847bac1f5ca64879216a08b4248b9c71560016ad Mon Sep 17 00:00:00 2001 From: Brody McKee Date: Sun, 11 Feb 2024 19:39:56 +1100 Subject: [PATCH 1/2] fix ups --- README.md | 18 ++++++++++++++++-- src/helpers/getCssExports.ts | 12 ++++++------ src/options.ts | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8129efd..525314a 100644 --- a/README.md +++ b/README.md @@ -152,11 +152,25 @@ The custom renderer itself should be a JavaScript file. The function will be cal module.exports = (css, { fileName, logger }) => { try { // ...process your css here. + + // Return the final string here. return renderedCss; - // css and sourceMap + } catch (error) { + logger.error(error.message); + } +}; +``` + +If you want to return a a source map, you can return an object from your exported function. + +```js +module.exports = (css, { fileName, logger }) => { + try { + // ...process your css here. + return { css: renderedCss, - map: sourceMap, + sourceMap: sourceMap, }; } catch (error) { logger.error(error.message); diff --git a/src/helpers/getCssExports.ts b/src/helpers/getCssExports.ts index aee6bd5..0637cb9 100644 --- a/src/helpers/getCssExports.ts +++ b/src/helpers/getCssExports.ts @@ -64,16 +64,16 @@ export const getCssExports = ({ if (options.customRenderer) { // eslint-disable-next-line @typescript-eslint/no-var-requires const customRenderer = require(options.customRenderer) as CustomRenderer; - const customResult = customRenderer(rawCss, { + const result = customRenderer(rawCss, { fileName, logger, compilerOptions, }); - if (typeof customResult === 'string') { - transformedCss = customResult; - } else if (customResult.css) { - transformedCss = customResult.css; - sourceMap = customResult.map; + if (typeof result === 'string') { + transformedCss = result; + } else if (result.css) { + transformedCss = result.css; + sourceMap = result.sourceMap; } } else { switch (fileType) { diff --git a/src/options.ts b/src/options.ts index 03069cc..3417f4e 100644 --- a/src/options.ts +++ b/src/options.ts @@ -57,7 +57,7 @@ export type CustomRenderer = ( | string | { css: string; - map?: RawSourceMap; + sourceMap?: RawSourceMap; }; export interface CustomTemplateOptions { From 55310f3b37f4ef5a01ce9833a714d4d85dbd5425 Mon Sep 17 00:00:00 2001 From: Brody McKee Date: Sun, 11 Feb 2024 19:45:25 +1100 Subject: [PATCH 2/2] chore: make post-merge changes --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 525314a..1d18a7a 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ module.exports = (css, { fileName, logger }) => { try { // ...process your css here. - // Return the final string here. + // `string` return renderedCss; } catch (error) { logger.error(error.message); @@ -169,7 +169,9 @@ module.exports = (css, { fileName, logger }) => { // ...process your css here. return { + // `string` css: renderedCss, + // `RawSourceMap` sourceMap: sourceMap, }; } catch (error) {