Resolver

A plugin type: Turn dependency requests into absolute paths (or exclude them)

Resolvers get called with an asset request (consisting of a source file path and the specifier of what is being requested) which it then attempts to resolve. If the resolver isn't sure how to handle a request, it can also return null and pass it to the next resolver in the chain.

import { Resolver } from "@parcel/plugin";

export default new Resolver({
async resolve({ filePath, dependency }) {
if (!shouldHandle(filePath)) {
return null;
}
// ...
return {
filePath: doResolve({ from: filePath, to: dependency.moduleSpecifier }),
};
},
});

The result object can also contain sideEffects (which corresponds to package.json#sideEffects) code (used instead of fs.readFile(filePath)) and isExcluded (e.g. to exclude node_modules).

ยถ Relevant API

ResolveResult website/generate-api-docs/example.flow:1014

type ResolveResultย = {|
  +filePath?: FilePath,
  +isExcluded?: boolean,
  +sideEffects?: boolean,
  +code?: string,
|}
Referenced by:
BaseAsset, Resolver

Resolver website/generate-api-docs/example.flow:1110

type Resolverย = {|
  resolve({|
    dependency: Dependency,
    options: PluginOptions,
    logger: PluginLogger,
    filePath: FilePath,
  |}): Async<?ResolveResult>,
|}