Skip to content

Support resolveImportMeta hook #1010

@underfin

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions