Sponsored Content
Skip to content

Support resolveImportMeta hook #1010

Description

@underfin

The resolveImportMeta hook gives a way to allows to customize import.meta and import.meta.someProperty, see here
https://rollupjs.org/plugin-development/#resolveimportmeta. Here has a example for it.

function importMetaUrlCurrentModulePlugin() {
	return {
		name: 'import-meta-url-current-module',
		resolveImportMeta(property, { moduleId }) {
			if (property === 'url') {
				return `'${pathToFileURL(moduleId).href}'`;
			}
			if (property == null) {
				return `{url:'${pathToFileURL(moduleId).href}'}`;
			}
			return null;
		}
	};
}

The hook will return string code to replace original import.meta.xx. Because the rolldown using Ast to codegen. It is difficult to implement it, it need to the oxc has some ways create ast from string, we could using parse at now. If you has good ideas, please let me know.

Metadata

Metadata

Assignees

No one assigned

    Fields

    Priority

    None yet

    Start date

    None yet

    Target date

    None yet

    Effort

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions