Skip to content

Commit

Permalink
chore: make post-merge change to customRenderer (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmckeb authored Feb 11, 2024
1 parent 86d2c78 commit 079fa27
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,27 @@ The custom renderer itself should be a JavaScript file. The function will be cal
module.exports = (css, { fileName, logger }) => {
try {
// ...process your css here.

// `string`
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 {
// `string`
css: renderedCss,
map: sourceMap,
// `RawSourceMap`
sourceMap: sourceMap,
};
} catch (error) {
logger.error(error.message);
Expand Down
12 changes: 6 additions & 6 deletions src/helpers/getCssExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export type CustomRenderer = (
| string
| {
css: string;
map?: RawSourceMap;
sourceMap?: RawSourceMap;
};

export interface CustomTemplateOptions {
Expand Down

0 comments on commit 079fa27

Please sign in to comment.