Offers an async require.\+resolve function. It\textquotesingle{}s highly configurable.\hypertarget{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8725}{}\doxysection{Features}\label{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8725}

\begin{DoxyItemize}
\item plugin system
\item provide a custom filesystem
\item sync and async node.\+js filesystems included
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8726}{}\doxysection{Getting Started}\label{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8726}
\hypertarget{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8727}{}\doxysubsection{Install}\label{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8727}

\begin{DoxyCode}{0}
\DoxyCodeLine{\# npm}
\DoxyCodeLine{npm install enhanced-\/resolve}
\DoxyCodeLine{\# or Yarn}
\DoxyCodeLine{yarn add enhanced-\/resolve }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8728}{}\doxysubsection{Creating a Resolver}\label{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8728}
The easiest way to create a resolver is to use the {\ttfamily create\+Resolver} function on {\ttfamily Resolve\+Factory}, along with one of the supplied File System implementations. 
\begin{DoxyCode}{0}
\DoxyCodeLine{const \{}
\DoxyCodeLine{  NodeJsInputFileSystem,}
\DoxyCodeLine{  CachedInputFileSystem,}
\DoxyCodeLine{  ResolverFactory}
\DoxyCodeLine{\} = require('enhanced-\/resolve');}
\DoxyCodeLine{}
\DoxyCodeLine{// create a resolver}
\DoxyCodeLine{const myResolver = ResolverFactory.createResolver(\{}
\DoxyCodeLine{  // Typical usage will consume the `NodeJsInputFileSystem` + `CachedInputFileSystem`, which wraps the Node.js `fs` wrapper to add resilience + caching.}
\DoxyCodeLine{  fileSystem: new CachedInputFileSystem(new NodeJsInputFileSystem(), 4000),}
\DoxyCodeLine{  extensions: ['.js', '.json']}
\DoxyCodeLine{  /* any other resolver options here. Options/defaults can be seen below */}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{// resolve a file with the new resolver}
\DoxyCodeLine{const context = \{\};}
\DoxyCodeLine{const resolveContext = \{\};}
\DoxyCodeLine{const lookupStartPath = '/Users/webpack/some/root/dir';}
\DoxyCodeLine{const request = './path/to-\/look-\/up.js';}
\DoxyCodeLine{myResolver.resolve(\{\}, lookupStartPath, request, resolveContext, (err/*Error*/, filepath/*string*/) => \{}
\DoxyCodeLine{  // Do something with the path}
\DoxyCodeLine{\}); }

\end{DoxyCode}


For more examples creating different types resolvers (sync/async, context, etc) see {\ttfamily lib/node.\+js}. \hypertarget{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8729}{}\doxysubsubsection{Resolver Options}\label{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8729}
\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{3}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Field   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Default   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Description    }\\\cline{1-3}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Field   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Default   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Description    }\\\cline{1-3}
\endhead
alias   &\mbox{[}\mbox{]}   &A list of module alias configurations or an object which maps key to value    \\\cline{1-3}
alias\+Fields   &\mbox{[}\mbox{]}   &A list of alias fields in description files    \\\cline{1-3}
cache\+With\+Context   &true   &If unsafe cache is enabled, includes {\ttfamily request.\+context} in the cache key    \\\cline{1-3}
description\+Files   &\mbox{[}\char`\"{}package.\+json\char`\"{}\mbox{]}   &A list of description files to read from    \\\cline{1-3}
enforce\+Extension   &false   &Enforce that a extension from extensions must be used    \\\cline{1-3}
enforce\+Module\+Extension   &false   &Enforce that a extension from module\+Extensions must be used    \\\cline{1-3}
extensions   &\mbox{[}\char`\"{}.\+js\char`\"{}, \char`\"{}.\+json\char`\"{}, \char`\"{}.\+node\char`\"{}\mbox{]}   &A list of extensions which should be tried for files    \\\cline{1-3}
main\+Fields   &\mbox{[}\char`\"{}main\char`\"{}\mbox{]}   &A list of main fields in description files    \\\cline{1-3}
main\+Files   &\mbox{[}\char`\"{}index\char`\"{}\mbox{]}   &A list of main files in directories    \\\cline{1-3}
modules   &\mbox{[}\char`\"{}node\+\_\+modules\char`\"{}\mbox{]}   &A list of directories to resolve modules from, can be absolute path or folder name    \\\cline{1-3}
unsafe\+Cache   &false   &Use this cache object to unsafely cache the successful requests    \\\cline{1-3}
plugins   &\mbox{[}\mbox{]}   &A list of additional resolve plugins which should be applied    \\\cline{1-3}
symlinks   &true   &Whether to resolve symlinks to their symlinked location    \\\cline{1-3}
cache\+Predicate   &function() \{ return true \};   &A function which decides whether a request should be cached or not. An object is passed to the function with {\ttfamily path} and {\ttfamily request} properties.    \\\cline{1-3}
module\+Extensions   &\mbox{[}\mbox{]}   &A list of module extensions which should be tried for modules    \\\cline{1-3}
resolve\+To\+Context   &false   &Resolve to a context instead of a file    \\\cline{1-3}
restrictions   &\mbox{[}\mbox{]}   &A list of resolve restrictions    \\\cline{1-3}
file\+System   &&The file system which should be used    \\\cline{1-3}
resolver   &undefined   &A prepared Resolver to which the plugins are attached   \\\cline{1-3}
\end{longtabu}
\hypertarget{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8730}{}\doxysection{Plugins}\label{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8730}
Similar to {\ttfamily webpack}, the core of {\ttfamily enhanced-\/resolve} functionality is implemented as individual plugins that are executed using \href{https://github.com/webpack/tapable}{\texttt{ {\ttfamily Tapable}}}. These plugins can extend the functionality of the library, adding other ways for files/contexts to be resolved.

A plugin should be a {\ttfamily class} (or its ES5 equivalent) with an {\ttfamily apply} method. The {\ttfamily apply} method will receive a {\ttfamily resolver} instance, that can be used to hook in to the event system.\hypertarget{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8731}{}\doxysubsection{Plugin Boilerplate}\label{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8731}

\begin{DoxyCode}{0}
\DoxyCodeLine{class MyResolverPlugin \{}
\DoxyCodeLine{  constructor(source, target) \{}
\DoxyCodeLine{    this.source = source;}
\DoxyCodeLine{    this.target = target;}
\DoxyCodeLine{  \}}
\DoxyCodeLine{}
\DoxyCodeLine{  apply(resolver) \{}
\DoxyCodeLine{    const target = resolver.ensureHook(this.target);}
\DoxyCodeLine{    resolver.getHook(this.source).tapAsync("{}MyResolverPlugin"{}, (request, resolveContext, callback) => \{}
\DoxyCodeLine{      // Any logic you need to create a new `request` can go here}
\DoxyCodeLine{      resolver.doResolve(target, request, null, resolveContext, callback);}
\DoxyCodeLine{    \});}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\} }

\end{DoxyCode}


Plugins are executed in a pipeline, and register which event they should be executed before/after. In the example above, {\ttfamily source} is the name of the event that starts the pipeline, and {\ttfamily target} is what event this plugin should fire, which is what continues the execution of the pipeline. For an example of how these different plugin events create a chain, see {\ttfamily lib/\+Resolver\+Factory.\+js}, in the {\ttfamily //// pipeline ////} section.\hypertarget{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8732}{}\doxysection{Tests}\label{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8732}

\begin{DoxyCode}{0}
\DoxyCodeLine{npm test }

\end{DoxyCode}


\href{http://travis-ci.org/webpack/enhanced-resolve}{\texttt{ }}\hypertarget{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8733}{}\doxysection{Passing options from webpack}\label{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8733}
If you are using {\ttfamily webpack}, and you want to pass custom options to {\ttfamily enhanced-\/resolve}, the options are passed from the {\ttfamily resolve} key of your webpack configuration e.\+g.\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{resolve: \{}
\DoxyCodeLine{  extensions: ['', '.js', '.jsx'],}
\DoxyCodeLine{  modules: ['src', 'node\_modules'],}
\DoxyCodeLine{  plugins: [new DirectoryNamedWebpackPlugin()]}
\DoxyCodeLine{  ...}
\DoxyCodeLine{\}, }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8734}{}\doxysection{License}\label{md_sfcode_node_modules_enhanced_resolve_README_autotoc_md8734}
Copyright (c) 2012-\/2016 Tobias Koppers

MIT (\href{http://www.opensource.org/licenses/mit-license.php}{\texttt{ http\+://www.\+opensource.\+org/licenses/mit-\/license.\+php}}) 