简体   繁体   中英

How to retrieve root entry point name in Webpack loader?

My use case is that i would like to build webpack loader to retrieving all translation method calls in my app. I want to make a map of translation keys in every entry point.

I'll use it later for lazy loading translations packs.

So I started to building my own loader. Getting all translation keys is a piece of cake. But I got stuck while searching for entry point name. I hoped to find it in the loaders this object, but I'm afraid that only information of currently parsed file is available.

Is there any way to retrieve parent entry point name of the curently parsed file in webpack loader?

Maybe loader query could help? Something like [name] in filename of output section of webpack configuration. I tried it, but it didn't worked. Maybe I'm doing something wrong. Any ideas?

I doubt you will be able to do it by entrypoint, you're better off just going by directory hierarchy.

Why? Because modules in Webpack can be required in multiple files/entrypoints, but only get transformed by a loader once. Going through the loader for every require would be a huge overhead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM