TransformAssetPlugin.js 805 B

1234567891011121314151617181920212223242526272829303132333435
  1. const RawSource = require('webpack-sources').RawSource;
  2. const pluginCompat = require('./util/plugin-compat');
  3. class TransformAssetPlugin {
  4. apply(compiler) {
  5. pluginCompat.tap(
  6. compiler,
  7. '_hardSourceFreezeAsset',
  8. 'TransformAssetPlugin freeze',
  9. (frozen, asset, extra) => asset.source(),
  10. );
  11. pluginCompat.tap(
  12. compiler,
  13. '_hardSourceThawAsset',
  14. 'TransformAssetPlugin thaw',
  15. (thawed, asset, extra) => {
  16. if (!thawed) {
  17. thawed = asset;
  18. if (thawed.type === 'buffer') {
  19. thawed = new Buffer(thawed);
  20. }
  21. if (!(thawed instanceof RawSource)) {
  22. thawed = new RawSource(thawed);
  23. }
  24. }
  25. return thawed;
  26. },
  27. );
  28. }
  29. }
  30. module.exports = TransformAssetPlugin;