SerializerFilePlugin.js 716 B

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