SerializerLeveldbPlugin.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const join = require('path').join;
  2. const pluginCompat = require('./util/plugin-compat');
  3. let LevelDbSerializer;
  4. let AppendSerializerPlugin;
  5. class HardSourceLevelDbSerializerPlugin {
  6. apply(compiler) {
  7. pluginCompat.tap(
  8. compiler,
  9. 'hardSourceCacheFactory',
  10. 'LevelDbSerializer',
  11. factory => info => {
  12. if (info.type === 'data') {
  13. return HardSourceLevelDbSerializerPlugin.createSerializer(info);
  14. }
  15. return factory(info);
  16. },
  17. );
  18. }
  19. }
  20. HardSourceLevelDbSerializerPlugin.createSerializer = info => {
  21. if (!LevelDbSerializer) {
  22. try {
  23. LevelDbSerializer = require('./SerializerLeveldb');
  24. } catch (e) {}
  25. }
  26. if (LevelDbSerializer) {
  27. return new LevelDbSerializer({
  28. cacheDirPath: join(info.cacheDirPath, info.name),
  29. });
  30. } else {
  31. if (!AppendSerializerPlugin) {
  32. AppendSerializerPlugin = require('./SerializerAppendPlugin');
  33. }
  34. return AppendSerializerPlugin.createSerializer(info);
  35. }
  36. };
  37. module.exports = HardSourceLevelDbSerializerPlugin;