SerializerAppendPlugin.js 969 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const join = require('path').join;
  2. const pluginCompat = require('./util/plugin-compat');
  3. let AppendSerializer;
  4. const _blockSizeByName = {
  5. data: 4 * 1024,
  6. md5: 128,
  7. 'missing-resolve': 256,
  8. module: 4 * 1024,
  9. 'module-resolve': 1024,
  10. resolver: 256,
  11. };
  12. class SerializerAppendPlugin {
  13. apply(compiler) {
  14. pluginCompat.tap(
  15. compiler,
  16. 'hardSourceCacheFactory',
  17. 'AppendSerializer',
  18. factory => info => {
  19. if (info.type === 'data') {
  20. return SerializerAppendPlugin.createSerializer(info);
  21. }
  22. return factory(info);
  23. },
  24. );
  25. }
  26. }
  27. SerializerAppendPlugin.createSerializer = ({
  28. cacheDirPath,
  29. name,
  30. autoParse,
  31. }) => {
  32. if (!AppendSerializer) {
  33. AppendSerializer = require('./SerializerAppend');
  34. }
  35. return new AppendSerializer({
  36. cacheDirPath: join(cacheDirPath, name),
  37. blockSize: _blockSizeByName[name],
  38. autoParse: autoParse,
  39. });
  40. };
  41. module.exports = SerializerAppendPlugin;