src/createWebpackLessPlugin.js
function createWebpackLessPlugin(loaderContext) {
  const { fs } = loaderContext;
  const resolve = pify(loaderContext.resolve.bind(loaderContext));
  const loadModule = pify(loaderContext.loadModule.bind(loaderContext));
  const readFile = pify(fs.readFile.bind(fs));

  class WebpackFileManager extends less.FileManager {
    supports() {
      // Our WebpackFileManager handles all the files
      return true;
    }

    // Sync resolving is used at least by the `data-uri` function.
    // This file manager doesn't know how to do it, so let's delegate it
    // to the default file manager of Less.
    // We could probably use loaderContext.resolveSync, but it's deprecated,
    // see https://webpack.js.org/api/loaders/#this-resolvesync
    supportsSync() {
      return false;
    }

    loadFile(filename, currentDirectory, options) {
      let url;
      if (less.version[0] >= 3) {
        if (options.ext && !isModuleName.test(filename)) {
          url = this.tryAppendExtension(filename, options.ext);
        } else {
          url = filename;
        }
      } else {
        url = filename.replace(matchMalformedModuleFilename, '$1');
      }
      const moduleRequest = loaderUtils.urlToRequest(
        url,
        url.charAt(0) === '/' ? '' : null
      );
      // Less is giving us trailing slashes, but the context should have no trailing slash
      const context = currentDirectory.replace(trailingSlash, '');
      let resolvedFilename;

      return resolve(context, moduleRequest)
        .then((f) => {
          resolvedFilename = f;
          loaderContext.addDependency(resolvedFilename);

          if (isLessCompatible.test(resolvedFilename)) {
            return readFile(resolvedFilename).then((contents) =>
              contents.toString('utf8')
            );
          }

          return loadModule([stringifyLoader, resolvedFilename].join('!')).then(
            JSON.parse
          );
        })
        .then((contents) => {
          return {
            contents,
            filename: resolvedFilename,
          };
        });
    }
  }

  return {
    install(lessInstance, pluginManager) {
      pluginManager.addFileManager(new WebpackFileManager());
    },
    minVersion: [2, 1, 1],
  };
}
function createWebpackLessPlugin(loaderContext) {
  const { fs } = loaderContext;
  const resolve = pify(loaderContext.resolve.bind(loaderContext));
  const loadModule = pify(loaderContext.loadModule.bind(loaderContext));
  const readFile = pify(fs.readFile.bind(fs));

  class WebpackFileManager extends less.FileManager {
    supports() {
      // Our WebpackFileManager handles all the files
      return true;
    }

    // Sync resolving is used at least by the `data-uri` function.
    // This file manager doesn't know how to do it, so let's delegate it
    // to the default file manager of Less.
    // We could probably use loaderContext.resolveSync, but it's deprecated,
    // see https://webpack.js.org/api/loaders/#this-resolvesync
    supportsSync() {
      return false;
    }

    loadFile(filename, currentDirectory, options) {
      let url;
      if (less.version[0] >= 3) {
        if (options.ext && !isModuleName.test(filename)) {
          url = this.tryAppendExtension(filename, options.ext);
        } else {
          url = filename;
        }
      } else {
        url = filename.replace(matchMalformedModuleFilename, '$1');
      }
      const moduleRequest = loaderUtils.urlToRequest(
        url,
        url.charAt(0) === '/' ? '' : null
      );
      // Less is giving us trailing slashes, but the context should have no trailing slash
      const context = currentDirectory.replace(trailingSlash, '');
      let resolvedFilename;

      return resolve(context, moduleRequest)
        .then((f) => {
          resolvedFilename = f;
          loaderContext.addDependency(resolvedFilename);

          if (isLessCompatible.test(resolvedFilename)) {
            return readFile(resolvedFilename).then((contents) =>
              contents.toString('utf8')
            );
          }

          return loadModule([stringifyLoader, resolvedFilename].join('!')).then(
            JSON.parse
          );
        })
        .then((contents) => {
          return {
            contents,
            filename: resolvedFilename,
          };
        });
    }
  }

  return {
    install(lessInstance, pluginManager) {
      pluginManager.addFileManager(new WebpackFileManager());
    },
    minVersion: [2, 1, 1],
  };
}
function createWebpackLessPlugin ( loaderContext ) { const { fs } = loaderContext ; const resolve = pify ( loaderContext . resolve . bind ( loaderContext ) ) ; const loadModule = pify ( loaderContext . loadModule . bind ( loaderContext ) ) ; const readFile = pify ( fs . readFile . bind ( fs ) ) ; class WebpackFileManager extends less . FileManager { supports ( ) { // Our WebpackFileManager handles all the files return true ; } // Sync resolving is used at least by the `data-uri` function. // This file manager doesn't know how to do it, so let's delegate it // to the default file manager of Less. // We could probably use loaderContext.resolveSync, but it's deprecated, // see https://webpack.js.org/api/loaders/#this-resolvesync supportsSync ( ) { return false ; } loadFile ( filename , currentDirectory , options ) { let url ; if ( less . version [ 0 ] >= 3 ) { if ( options . ext && ! isModuleName . test ( filename ) ) { url = this . tryAppendExtension ( filename , options . ext ) ; } else { url = filename ; } } else { url = filename . replace ( matchMalformedModuleFilename , '$1' ) ; } const moduleRequest = loaderUtils . urlToRequest ( url , url . charAt ( 0 ) === '/' ? '' : null ) ; // Less is giving us trailing slashes, but the context should have no trailing slash const context = currentDirectory . replace ( trailingSlash , '' ) ; let resolvedFilename ; return resolve ( context , moduleRequest ) . then ( ( f ) => { resolvedFilename = f ; loaderContext . addDependency ( resolvedFilename ) ; if ( isLessCompatible . test ( resolvedFilename ) ) { return readFile ( resolvedFilename ) . then ( ( contents ) => contents . toString ( 'utf8' ) ) ; } return loadModule ( [ stringifyLoader , resolvedFilename ] . join ( '!' ) ) . then ( JSON . parse ) ; } ) . then ( ( contents ) => { return { contents , filename : resolvedFilename , } ; } ) ; } } return { install ( lessInstance , pluginManager ) { pluginManager . addFileManager ( new WebpackFileManager ( ) ) ; } , minVersion : [ 2 , 1 , 1 ] , } ; }
Creates a Less plugin that uses webpack's resolving engine that is provided by the loaderContext.

@param {LoaderContext} loaderContext
@param {string=} root
@returns {LessPlugin}
Creates a Less plugin that uses webpack s resolving engine that is provided by the loaderContext .