Back to Rolldown

Plugin Context Getmoduleinfo

packages/rolldown/src/plugin/docs/plugin-context-getmoduleinfo.md

0.15.12.7 KB
Original Source

During the build, this object represents currently available information about the module which may be inaccurate before the buildEnd hook:

  • id will never change.
  • code, exports are only available after parsing, i.e. in the moduleParsed hook or after awaiting this.load. At that point, they will no longer change.
  • isEntry is true, it will no longer change. It is however possible for modules to become entry points after they are parsed, either via this.emitFile or because a plugin inspects a potential entry point via this.load in the resolveId hook when resolving an entry point. Therefore, it is not recommended relying on this flag in the transform hook. It will no longer change after buildEnd.
  • importers and dynamicImporters will start as empty arrays, which receive additional entries as new importers and are discovered. They will no longer change after buildEnd.
  • importedIds and dynamicallyImportedIds are available when a module has been parsed and its dependencies have been resolved. This is the case in the moduleParsed hook or after awaiting this.load with the resolveDependencies flag. At that point, they will no longer change.
  • meta and moduleSideEffects can be changed by load and transform hooks. Moreover, while most properties are read-only, these properties are writable and changes will be picked up if they occur before the buildEnd hook is triggered. meta itself should not be overwritten, but it is ok to mutate its properties at any time to store meta information about a module. The advantage of doing this instead of keeping state in a plugin is that meta is persisted to and restored from the cache if it is used, e.g. when using watch mode from the CLI.