Skip to content

Commit

Permalink
feat: optimize debug message formatting, #1065
Browse files Browse the repository at this point in the history
docs: add impofration how to enable @debug output
  • Loading branch information
webdiscus committed Jun 16, 2022
1 parent 2e1822e commit 21e00a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,19 @@ module.exports = {
};
```

## How to enable `@debug` output

Defaults, the output of `@debug` messages is disabled.
To enable it, add to **webpack.config.js** following:
```js
module.exports = {
stats: {
loggingDebug: ['sass-loader'],
},
//...
}
```

## Examples

### Extracts CSS into separate files
Expand Down
4 changes: 3 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,15 @@ async function getSassOptions(
const logger = loaderContext.getLogger("sass-loader");
const formatSpan = (span) =>
`${span.url || "-"}:${span.start.line}:${span.start.column}: `;
const formatDebugSpan = (span) =>
`[debug:${span.start.line}:${span.start.column}] `;

options.logger = {
debug(message, loggerOptions) {
let builtMessage = "";

if (loggerOptions.span) {
builtMessage = formatSpan(loggerOptions.span);
builtMessage = formatDebugSpan(loggerOptions.span);
}

builtMessage += message;
Expand Down

0 comments on commit 21e00a7

Please sign in to comment.