TransformModuleAssetsPlugin.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const pluginCompat = require('./util/plugin-compat');
  2. class TransformModuleAssetsPlugin {
  3. apply(compiler) {
  4. let store;
  5. let fetch;
  6. pluginCompat.tap(
  7. compiler,
  8. '_hardSourceMethods',
  9. 'TransformModuleAssetsPlugin copy methods',
  10. methods => {
  11. store = methods.store;
  12. fetch = methods.fetch;
  13. // freeze = methods.freeze;
  14. // thaw = methods.thaw;
  15. // mapFreeze = methods.mapFreeze;
  16. // mapThaw = methods.mapThaw;
  17. },
  18. );
  19. pluginCompat.tap(
  20. compiler,
  21. '_hardSourceFreezeModuleAssets',
  22. 'TransformModuleAssetsPlugin freeze',
  23. (frozen, assets, extra) => {
  24. if (!frozen && assets) {
  25. Object.keys(assets).forEach(key => {
  26. store('Asset', key, assets[key], extra);
  27. });
  28. frozen = Object.keys(assets);
  29. }
  30. return frozen;
  31. },
  32. );
  33. pluginCompat.tap(
  34. compiler,
  35. '_hardSourceThawModuleAssets',
  36. 'TransformModuleAssetsPlugin thaw',
  37. (assets, frozen, extra) => {
  38. if (!assets && frozen) {
  39. assets = {};
  40. frozen.forEach(key => {
  41. assets[key] = fetch('Asset', key, extra);
  42. });
  43. }
  44. return assets;
  45. },
  46. );
  47. }
  48. }
  49. module.exports = TransformModuleAssetsPlugin;