* Creates a Less plugin that uses webpack's resolving engine that is provided by the loaderContext. * @param {LoaderContext} loaderContext loader context * @param {Less} implementation implementation * @param {Promise []} pendingDependencyTasks pending dependency tasks * @returns {LessPlugi
( loaderContext, implementation, pendingDependencyTasks, )
| 63 | * @returns {LessPlugin} less plugin |
| 64 | */ |
| 65 | function createWebpackLessPlugin( |
| 66 | loaderContext, |
| 67 | implementation, |
| 68 | pendingDependencyTasks, |
| 69 | ) { |
| 70 | const lessOptions = |
| 71 | /** @type {LoaderOptions} */ |
| 72 | (loaderContext.getOptions()); |
| 73 | const resolve = loaderContext.getResolve({ |
| 74 | dependencyType: "less", |
| 75 | conditionNames: ["less", "style", "..."], |
| 76 | mainFields: ["less", "style", "main", "..."], |
| 77 | mainFiles: ["index", "..."], |
| 78 | extensions: [".less", ".css"], |
| 79 | preferRelative: true, |
| 80 | }); |
| 81 | |
| 82 | class WebpackFileManager extends implementation.FileManager { |
| 83 | /** |
| 84 | * @param {string} filename filename |
| 85 | * @returns {boolean} true when filename is supported, otherwise false |
| 86 | */ |
| 87 | supports(filename) { |
| 88 | if (filename[0] === "/" || IS_NATIVE_WIN32_PATH.test(filename)) { |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | if (this.isPathAbsolute(filename)) { |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | // Sync loading is used by `data-uri()` and any custom Less function |
| 100 | // (including those installed via `@plugin`). Webpack doesn't expose a |
| 101 | // sync resolver, so we fulfil the sync read by delegating to Less's |
| 102 | // default file manager (which can only handle native filesystem paths) |
| 103 | // and, in parallel, kick off an async webpack resolve so the loaded |
| 104 | // file is tracked as a webpack file dependency. Without this, webpack's |
| 105 | // persistent cache won't invalidate when a sync-loaded file changes. |
| 106 | // See https://github.com/webpack/less-loader/issues/492. |
| 107 | /** |
| 108 | * @returns {boolean} true when support sync, otherwise false |
| 109 | */ |
| 110 | supportsSync() { |
| 111 | return true; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * @param {string} filename filename |
| 116 | * @param {string} currentDirectory current directory |
| 117 | * @param {LoadFileOptions} options options |
| 118 | * @param {Environment} environment environment |
| 119 | * @returns {LoadFileResult} loaded file |
| 120 | */ |
| 121 | loadFileSync(filename, currentDirectory, options, environment) { |
| 122 | // The default Less `loadFileSync` internally dispatches to |
no outgoing calls
no test coverage detected
searching dependent graphs…