问题
Explanation
I'm developing a webpack custom loader, that is in charge of parsing the javascript and search for certain text using regex.
I need to have a way to collect the data between each parsed file and finally pass that data to a related plugin, so that the plugin can make the appropriate action with that data.
My failed strategy
I can use a module to share data between loader calls, but this data is not available in the plugins.
Suggestions ?
I've been looking at the way the extract-text-plugin does it, since it has a loader and a plugin, but looking at their source code, the way they declare the module is strange to me and I can't really grasp their strategy.
Thanks for any help!
回答1:
Using a shared module is a viable option, I created a loader/plugin combo that creates an SVG sprite from svgs imported through the loader, here is the repository: https://github.com/crystal-ball/svg-symbol-sprite-loader
Here is how I setup the process:
- I export a singleton as the sprite-store
- The loader requires the sprite store and adds any imported SVG to the store.
- In the additional assets hook the plugin reads all of the collected data from the sprite store.
来源:https://stackoverflow.com/questions/46308248/webpack-share-data-between-custom-loader-and-plugin