Reputation: 3542
I'm working on a plugin that collects exports with a particular name from the modules. I've gotten the data out of the individual files via the parser export hooks, but I can't seem to find out how to pull out the actual module that the parser is operating on.
// hook into the module factory and get the exports
compiler.hooks.normalModuleFactory.tap(pluginName, factory => {
factory.hooks.parser.for('javascript/auto').tap(pluginName, parser => {
parser.hooks.export.tap(pluginName, (node) => {
this.parseMetadataNode(node);
});
});
});
parseMetadataNode is the method that does the actual extraction of the export, which is working well.
How do I find the module or userRequest that the node is operating on? I need the file name of that node!
Upvotes: 3
Views: 715
Reputation: 51
You can probably check parser.state
compiler.hooks.normalModuleFactory.tap(pluginName, factory => {
factory.hooks.parser.for('javascript/auto').tap(pluginName, parser => {
parser.hooks.export.tap(pluginName, (node) => {
const { module: { rawRequest } } = parser.state;
// ..
});
});
});
Upvotes: 5