How to use the enhanced-resolve.loader function in enhanced-resolve

To help you get started, we’ve selected a few enhanced-resolve examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gajus / isomorphic-webpack / src / utilities / resolveRequest.js View on Github external
// @flow

import path from 'path';
import enhancedResolve from 'enhanced-resolve';
import isRequestInRequestMap from './isRequestInRequestMap';

const resolveLoaderSync = enhancedResolve.loader.sync;

export default (context: string, requestMap: Object, request: string, parentFilename: string): any => {
  const loaders = request.split('!');
  const requestFilePath = loaders.pop();

  const resolvedLoaders = loaders
    .map((loader: string): string => {
      // @todo What is the purpose of the context parameter?
      return resolveLoaderSync({}, parentFilename, loader);
    })
    .map((loaderAbsolutePath: string): string => {
      return path.relative(context, loaderAbsolutePath);
    });

  const absoluteRequestPath = path.resolve(path.dirname(parentFilename), requestFilePath);
  const relativeTargetResourcePath = './' + path.relative(context, absoluteRequestPath);