* Webpack loader that compiles Less to CSS. * @this {LoaderContext} * @param {string} content content * @returns {Promise } loader result
(content)
| 22 | * @returns {Promise<void>} loader result |
| 23 | */ |
| 24 | async function lessLoader(content) { |
| 25 | const options = this.getOptions(/** @type {Schema} */ (schema)); |
| 26 | const callback = this.async(); |
| 27 | let implementation; |
| 28 | |
| 29 | try { |
| 30 | implementation = await getLessImplementation(this, options.implementation); |
| 31 | } catch (error) { |
| 32 | callback(/** @type {Error} */ (error)); |
| 33 | |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | if (!implementation) { |
| 38 | callback( |
| 39 | new Error( |
| 40 | `The Less implementation "${options.implementation}" not found`, |
| 41 | ), |
| 42 | ); |
| 43 | |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | const { lessOptions, pendingDependencyTasks } = getLessOptions( |
| 48 | this, |
| 49 | options, |
| 50 | implementation, |
| 51 | ); |
| 52 | const useSourceMap = |
| 53 | typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap; |
| 54 | |
| 55 | if (useSourceMap) { |
| 56 | lessOptions.sourceMap = { |
| 57 | sourceMapBasepath: "", |
| 58 | outputSourceFiles: true, |
| 59 | // @ts-expect-error bad types |
| 60 | disableSourcemapAnnotation: true, |
| 61 | }; |
| 62 | } |
| 63 | |
| 64 | let data = content; |
| 65 | |
| 66 | if (typeof options.additionalData !== "undefined") { |
| 67 | data = |
| 68 | typeof options.additionalData === "function" |
| 69 | ? `${await options.additionalData(data, this)}` |
| 70 | : `${options.additionalData}\n${data}`; |
| 71 | } |
| 72 | |
| 73 | const logger = this.getLogger("less-loader"); |
| 74 | const loaderContext = this; |
| 75 | const lessLogAsWarnOrErr = options.lessLogAsWarnOrErr !== false; |
| 76 | const loggerListener = { |
| 77 | /** @param {string} message message */ |
| 78 | error(message) { |
| 79 | if (lessLogAsWarnOrErr) { |
| 80 | loaderContext.emitError(new Error(message)); |
| 81 | } else { |
nothing calls this directly
no test coverage detected
searching dependent graphs…