Skip to content

Commit 079fa27

Browse files
authored
chore: make post-merge change to customRenderer (#257)
1 parent 86d2c78 commit 079fa27

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

README.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,27 @@ The custom renderer itself should be a JavaScript file. The function will be cal
152152
module.exports = (css, { fileName, logger }) => {
153153
try {
154154
// ...process your css here.
155+
156+
// `string`
155157
return renderedCss;
156-
// css and sourceMap
158+
} catch (error) {
159+
logger.error(error.message);
160+
}
161+
};
162+
```
163+
164+
If you want to return a a source map, you can return an object from your exported function.
165+
166+
```js
167+
module.exports = (css, { fileName, logger }) => {
168+
try {
169+
// ...process your css here.
170+
157171
return {
172+
// `string`
158173
css: renderedCss,
159-
map: sourceMap,
174+
// `RawSourceMap`
175+
sourceMap: sourceMap,
160176
};
161177
} catch (error) {
162178
logger.error(error.message);

src/helpers/getCssExports.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ export const getCssExports = ({
6464
if (options.customRenderer) {
6565
// eslint-disable-next-line @typescript-eslint/no-var-requires
6666
const customRenderer = require(options.customRenderer) as CustomRenderer;
67-
const customResult = customRenderer(rawCss, {
67+
const result = customRenderer(rawCss, {
6868
fileName,
6969
logger,
7070
compilerOptions,
7171
});
72-
if (typeof customResult === 'string') {
73-
transformedCss = customResult;
74-
} else if (customResult.css) {
75-
transformedCss = customResult.css;
76-
sourceMap = customResult.map;
72+
if (typeof result === 'string') {
73+
transformedCss = result;
74+
} else if (result.css) {
75+
transformedCss = result.css;
76+
sourceMap = result.sourceMap;
7777
}
7878
} else {
7979
switch (fileType) {

src/options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export type CustomRenderer = (
5757
| string
5858
| {
5959
css: string;
60-
map?: RawSourceMap;
60+
sourceMap?: RawSourceMap;
6161
};
6262

6363
export interface CustomTemplateOptions {

0 commit comments

Comments
 (0)