TransformCompilationPlugin.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const cachePrefix = require('./util').cachePrefix;
  2. const logMessages = require('./util/log-messages');
  3. const pluginCompat = require('./util/plugin-compat');
  4. class TransformCompilationPlugin {
  5. apply(compiler) {
  6. let store;
  7. pluginCompat.tap(
  8. compiler,
  9. '_hardSourceMethods',
  10. 'TransformCompilationPlugin copy methods',
  11. methods => {
  12. store = methods.store;
  13. // fetch = methods.fetch;
  14. // freeze = methods.freeze;
  15. // thaw = methods.thaw;
  16. },
  17. );
  18. pluginCompat.tap(
  19. compiler,
  20. '_hardSourceFreezeCompilation',
  21. 'TransformCompilationPlugin freeze',
  22. (_, compilation) => {
  23. compilation.modules.forEach(module => {
  24. const identifierPrefix = cachePrefix(compilation);
  25. if (identifierPrefix === null) {
  26. return;
  27. }
  28. const identifier = identifierPrefix + module.identifier();
  29. try {
  30. store('Module', identifier, module, {
  31. id: identifier,
  32. compilation,
  33. });
  34. } catch (e) {
  35. logMessages.moduleFreezeError(compilation, module, e);
  36. }
  37. });
  38. },
  39. );
  40. }
  41. }
  42. module.exports = TransformCompilationPlugin;