Skip to content

Commit 6fbb647

Browse files
feat!: enable lessLogAsWarnOrErr by default (#600)
1 parent 1de4ccd commit 6fbb647

4 files changed

Lines changed: 16 additions & 14 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"less-loader": major
3+
---
4+
5+
`lessLogAsWarnOrErr` now defaults to `true`. Less warnings and errors are emitted as webpack warnings and errors by default. Set the option to `false` to restore the previous behavior of logging silently.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ Type:
429429
type lessLogAsWarnOrErr = boolean;
430430
```
431431

432-
Default: `false`
432+
Default: `true`
433433

434434
`Less` warnings and errors will be treated as webpack warnings and errors, instead of being logged silently.
435435

@@ -441,7 +441,7 @@ div {
441441
}
442442
```
443443

444-
If `lessLogAsWarnOrErr` is set to `false` it will be just a log and webpack will compile successfully, but if you set this option to `true` webpack will compile fail with a warning(or error), and can break the build if configured accordingly.
444+
If `lessLogAsWarnOrErr` is set to `false` it will be just a log and webpack will compile successfully, but if you leave the default value (or set this option to `true`) webpack will compile fail with a warning(or error), and can break the build if configured accordingly.
445445

446446
**webpack.config.js**
447447

src/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,19 @@ async function lessLoader(content) {
7272

7373
const logger = this.getLogger("less-loader");
7474
const loaderContext = this;
75+
const lessLogAsWarnOrErr = options.lessLogAsWarnOrErr !== false;
7576
const loggerListener = {
7677
/** @param {string} message message */
7778
error(message) {
78-
// TODO enable by default in the next major release
79-
if (options.lessLogAsWarnOrErr) {
79+
if (lessLogAsWarnOrErr) {
8080
loaderContext.emitError(new Error(message));
8181
} else {
8282
logger.error(message);
8383
}
8484
},
8585
/** @param {string} message message */
8686
warn(message) {
87-
// TODO enable by default in the next major release
88-
if (options.lessLogAsWarnOrErr) {
87+
if (lessLogAsWarnOrErr) {
8988
loaderContext.emitWarning(new Error(message));
9089
} else {
9190
logger.warn(message);

test/__snapshots__/loader.test.js.snap

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,9 @@ exports[`loader > should work and have loaderContext in less plugins 1`] = `
475475
`;
476476
477477
exports[`loader > should work and have loaderContext in less plugins 2`] = `
478-
[]
478+
[
479+
"ModuleWarning: Module Warning (from \`replaced original path\`):\\nDEPRECATED WARNING: The @plugin directive is deprecated and will be replaced in Less 5.x. Use --plugin CLI option or the programmatic plugin API instead. in /test/fixtures/basic-plugins-2.less on line 1, column 1:"
480+
]
479481
`;
480482
481483
exports[`loader > should work and have loaderContext in less plugins 3`] = `
@@ -489,12 +491,6 @@ exports[`loader > should work and logging 1`] = `
489491
exports[`loader > should work and logging 2`] = `
490492
[
491493
[
492-
{
493-
"type": "warn",
494-
"args": [
495-
"WARNING: extend ' .inline' has no matches"
496-
]
497-
},
498494
{
499495
"type": "log",
500496
"args": [
@@ -506,7 +502,9 @@ exports[`loader > should work and logging 2`] = `
506502
`;
507503
508504
exports[`loader > should work and logging 3`] = `
509-
[]
505+
[
506+
"ModuleWarning: Module Warning (from \`replaced original path\`):\\nWARNING: extend ' .inline' has no matches"
507+
]
510508
`;
511509
512510
exports[`loader > should work and logging 4`] = `

0 commit comments

Comments
 (0)