Skip to content

Commit d4471b4

Browse files
authored
Document how resolveId is cached (#4407)
1 parent 5bd96df commit d4471b4

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

docs/05-plugin-development.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ Note that while `resolveId` will be called for each import of a module and can t
262262

263263
When triggering this hook from a plugin via [`this.resolve`](guide/en/#thisresolve), it is possible to pass a custom options object to this hook. While this object will be passed unmodified, plugins should follow the convention of adding a `custom` property with an object where the keys correspond to the names of the plugins that the options are intended for. For details see [custom resolver options](guide/en/#custom-resolver-options).
264264

265+
In watch mode or when using the cache explicitly, the resolved imports of a cached module are also taken from the cache and not determined via the `resolveId` hook again. To prevent this, you can return `true` from the [`shouldTransformCachedModule`](guide/en/#shouldtransformcachedmodule) hook for that module. This will remove the module and its import resolutions from cache and call `transform` and `resolveId` again.
266+
265267
#### `shouldTransformCachedModule`
266268

267269
**Type:** `({id: string, code: string, ast: ESTree.Program, meta: {[plugin: string]: any}, moduleSideEffects: boolean | "no-treeshake", syntheticNamedExports: string | boolean}) => boolean`<br> **Kind:** `async, first`<br> **Previous Hook:** [`load`](guide/en/#load) where the cached file was loaded to compare its code with the cached version.<br> **Next Hook:** [`moduleParsed`](guide/en/#moduleparsed) if no plugin returns `true`, otherwise [`transform`](guide/en/#transform).
@@ -278,7 +280,9 @@ If a plugin does not return `true`, Rollup will trigger this hook for other plug
278280

279281
Can be used to transform individual modules. To prevent additional parsing overhead in case e.g. this hook already used `this.parse` to generate an AST for some reason, this hook can optionally return a `{ code, ast, map }` object. The `ast` must be a standard ESTree AST with `start` and `end` properties for each node. If the transformation does not move code, you can preserve existing sourcemaps by setting `map` to `null`. Otherwise you might need to generate the source map. See [the section on source code transformations](#source-code-transformations).
280282

281-
Note that in watch mode, the result of this hook is cached when rebuilding and the hook is only triggered again for a module `id` if either the `code` of the module has changed or a file has changed that was added via `this.addWatchFile` the last time the hook was triggered for this module.
283+
Note that in watch mode or when using the cache explicitly, the result of this hook is cached when rebuilding and the hook is only triggered again for a module `id` if either the `code` of the module has changed or a file has changed that was added via `this.addWatchFile` the last time the hook was triggered for this module.
284+
285+
In all other cases, the [`shouldTransformCachedModule`](guide/en/#shouldtransformcachedmodule) hook is triggered instead, which gives access to the cached module. Returning `true` from `shouldTransformCachedModule` will remove the module from cache and instead call `transform` again.
282286

283287
You can also use the object form of the return value to configure additional properties of the module. Note that it's possible to return only properties and no code transformations.
284288

docs/build-hooks.mmd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ flowchart TB
33
classDef hook-sequential fill:#ffd2b3,stroke:#000;
44
classDef hook-first fill:#fff2b3,stroke:#000;
55
classDef hook-sequential-sync fill:#ffd2b3,stroke:#f00;
6+
classDef hook-first-sync fill:#fff2b3,stroke:#f00;
67

78
buildend("buildEnd"):::hook-parallel
89
click buildend "/guide/en/#buildend" _parent
@@ -60,7 +61,10 @@ flowchart TB
6061
--> |non-external|load
6162

6263
moduleparsed
63-
--> |each import|resolveid
64+
--> |"each import\n(cached)"|load
65+
66+
moduleparsed
67+
--> |"each import\n(not cached)"|resolveid
6468

6569
resolvedynamicimport
6670
.-> |external|buildend

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy