0

I'm making a rollup-compatible plugin in Vite. (so basically a rollup-plugin).
I am using the transform hook in the plugin. The plugin takes a module name(as specified in package.json, for example "d3") as a parameter, and I want to use this parameter to apply the plugin only on the specific module.

The transform function has parameters id and code. I assumed id was the module name but it seems to be the path of the file that gets resolved when running the module.

transform(code: string, id: string) {
    if(id === module_name) {
        // do stuff
    }
    return null;
}

So, is there a way to find out the module name in the transform hook so that I can apply the plugin only on the module specified in Vite's config?

Mahesh Bansod
  • 1,493
  • 2
  • 24
  • 42

0 Answers0