convert-string-to-asset.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. /*
  3. Copyright 2018 Google LLC
  4. Use of this source code is governed by an MIT-style
  5. license that can be found in the LICENSE file or at
  6. https://opensource.org/licenses/MIT.
  7. */
  8. /**
  9. * In webpack jargon: a compilation object represents a build of versioned
  10. * `assets`. The `compilation.assets` property of a compilation is a map of
  11. * filepaths -> asset objects. Each asset object has a property `source()` that
  12. * returns a string of that asset.
  13. *
  14. * `source` and `size` are the only required properties of a webpack asset.
  15. *
  16. * @typedef {Object} WebpackAsset
  17. *
  18. * @property {Function} source Returns a string representation of the asset that
  19. * will be written to the file system (or generated in-memory) by
  20. * webpack.
  21. * @property {Function} size Returns the byte size of the asset `source` value.
  22. *
  23. * @private
  24. */
  25. /**
  26. * Creates a webpack asset from a string that can be added to a compilation.
  27. *
  28. * @param {string} assetAsString String representation of the asset that should
  29. * be written to the file system by webpack.
  30. * @return {WebpackAsset}
  31. *
  32. * @private
  33. */
  34. function convertStringToAsset(assetAsString) {
  35. return {
  36. source: () => assetAsString,
  37. size: () => assetAsString.length
  38. };
  39. }
  40. module.exports = convertStringToAsset;