You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/05-plugin-development.md
+12-2Lines changed: 12 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -122,7 +122,7 @@ This hook is called each time a module has been fully parsed by Rollup. See [`th
122
122
123
123
In contrast to the [`transform`](guide/en/#transform) hook, this hook is never cached and can be used to get information about both cached and other modules, including the final shape of the `meta` property, the `code` and the `ast`.
124
124
125
-
This hook will wait until all imports are resolved so that the information in `moduleInfo.importedIds`and `moduleInfo.dynamicallyImportedIds` is complete and accurate. Note however that information about importing modules may be incomplete as additional importers could be discovered later. If you need this information, use the [`buildEnd`](guide/en/#buildend) hook.
125
+
This hook will wait until all imports are resolved so that the information in `moduleInfo.importedIds`, `moduleInfo.dynamicallyImportedIds`, `moduleInfo.importedIdResolutions`, and `moduleInfo.dynamicallyImportedIdResolutions` is complete and accurate. Note however that information about importing modules may be incomplete as additional importers could be discovered later. If you need this information, use the [`buildEnd`](guide/en/#buildend) hook.
126
126
127
127
#### `options`
128
128
@@ -677,15 +677,25 @@ type ModuleInfo = {
677
677
isExternal: boolean; // for external modules that are referenced but not included in the graph
678
678
isIncluded: boolean |null; // is the module included after tree-shaking, `null` if external or not yet available
679
679
importedIds: string[]; // the module ids statically imported by this module
680
+
importedIdResolutions: ResolvedId[]; // how statically imported ids were resolved, for use with this.load
680
681
importers: string[]; // the ids of all modules that statically import this module
681
682
dynamicallyImportedIds: string[]; // the module ids imported by this module via dynamic import()
683
+
dynamicallyImportedIdResolutions: ResolvedId[]; // how ids imported via dynamic import() were resolved
682
684
dynamicImporters: string[]; // the ids of all modules that import this module via dynamic import()
683
685
implicitlyLoadedAfterOneOf: string[]; // implicit relationships, declared via this.emitFile
684
686
implicitlyLoadedBefore: string[]; // implicit relationships, declared via this.emitFile
685
687
hasModuleSideEffects: boolean |'no-treeshake'; // are imports of this module included if nothing is imported from it
686
688
meta: { [plugin: string]: any }; // custom module meta-data
687
689
syntheticNamedExports: boolean | string; // final value of synthetic named exports
688
690
};
691
+
692
+
type ResolvedId = {
693
+
id: string; // the id of the imported module
694
+
external: boolean |'absolute'; // is this module external, "absolute" means it will not be rendered as relative in the module
695
+
moduleSideEffects: boolean |'no-treeshake'; // are side effects of the module observed, is tree-shaking enabled
696
+
syntheticNamedExports: boolean | string; // does the module allow importing non-existing named exports
697
+
meta: { [plugin: string]: any }; // custom module meta-data when resolving the module
698
+
};
689
699
```
690
700
691
701
During the build, this object represents currently available information about the module. Before the [`buildEnd`](guide/en/#buildend) hook, this information may be incomplete as e.g. the `importedIds` are not yet resolved or additional `importers` are discovered.
@@ -706,7 +716,7 @@ Loads and parses the module corresponding to the given id, attaching additional
706
716
707
717
This allows you to inspect the final content of modules before deciding how to resolve them in the [`resolveId`](guide/en/#resolveid) hook and e.g. resolve to a proxy module instead. If the module becomes part of the graph later, there is no additional overhead from using this context function as the module will not be parsed again. The signature allows you to directly pass the return value of [`this.resolve`](guide/en/#thisresolve) to this function as long as it is neither `null` nor external.
708
718
709
-
The returned promise will resolve once the module has been fully transformed and parsed but before any imports have been resolved. That means that the resulting `ModuleInfo` will have empty `importedIds`and `dynamicallyImportedIds`. This helps to avoid deadlock situations when awaiting `this.load` in a `resolveId` hook. If you are interested in `importedIds` and `dynamicallyImportedIds`, you should implement a `moduleParsed` hook.
719
+
The returned promise will resolve once the module has been fully transformed and parsed but before any imports have been resolved. That means that the resulting `ModuleInfo` will have empty `importedIds`, `dynamicallyImportedIds`, `importedIdResolutions`and `dynamicallyImportedIdResolutions`. This helps to avoid deadlock situations when awaiting `this.load` in a `resolveId` hook. If you are interested in `importedIds` and `dynamicallyImportedIds`, you should implement a `moduleParsed` hook.
710
720
711
721
Note that with regard to the `moduleSideEffects`, `syntheticNamedExports` and `meta` options, the same restrictions apply as for the `resolveId` hook: Their values only have an effect if the module has not been loaded yet. Thus, it is very important to use `this.resolve` first to find out if any plugins want to set special values for these options in their `resolveId` hook, and pass these options on to `this.load` if appropriate. The example below showcases how this can be handled to add a proxy module for modules containing a special code comment:
0 commit comments