SerializerCacachePlugin.js 746 B

123456789101112131415161718192021222324252627282930313233
  1. const join = require('path').join;
  2. const pluginCompat = require('./util/plugin-compat');
  3. let CacacheSerializer;
  4. class SerializerCacachePlugin {
  5. apply(compiler) {
  6. pluginCompat.tap(
  7. compiler,
  8. 'hardSourceCacheFactory',
  9. 'CacacheSerializer',
  10. factory => info => {
  11. if (info.type === 'data') {
  12. return SerializerCacachePlugin.createSerializer(info);
  13. }
  14. return factory(info);
  15. },
  16. );
  17. }
  18. }
  19. SerializerCacachePlugin.createSerializer = ({ cacheDirPath, name }) => {
  20. if (!CacacheSerializer) {
  21. CacacheSerializer = require('./SerializerCacache');
  22. }
  23. return new CacacheSerializer({
  24. cacheDirPath: join(cacheDirPath, name),
  25. });
  26. };
  27. module.exports = SerializerCacachePlugin;