replace-in-module-source.js 635 B

1234567891011121314151617181920
  1. const replaceSpritePlaceholder = require('./replace-sprite-placeholder');
  2. /**
  3. * @param {NormalModule|ExtractedModule} module
  4. * @param {Object<string, string>} replacements
  5. * @return {NormalModule|ExtractedModule}
  6. */
  7. function replaceInModuleSource(module, replacements) {
  8. const source = module._source;
  9. if (typeof source === 'string') {
  10. module._source = replaceSpritePlaceholder(source, replacements);
  11. } else if (typeof source === 'object' && typeof source._value === 'string') {
  12. source._value = replaceSpritePlaceholder(source._value, replacements);
  13. }
  14. return module;
  15. }
  16. module.exports = replaceInModuleSource;