proxyCustomImporters.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. /**
  3. * Creates new custom importers that use the given `resourcePath` if libsass calls the custom importer with `prev`
  4. * being 'stdin'.
  5. *
  6. * Why do we need this? We have to use the `data` option of node-sass in order to compile our sass because
  7. * the `resourcePath` might not be an actual file on disk. When using the `data` option, libsass uses the string
  8. * 'stdin' instead of a filename.
  9. *
  10. * We have to fix this behavior in order to provide a consistent experience to the webpack user.
  11. *
  12. * @param {Function|Array<Function>} importer
  13. * @param {string} resourcePath
  14. * @returns {Array<Function>}
  15. */
  16. function proxyCustomImporters(importer, resourcePath) {
  17. return [].concat(importer).map(
  18. // eslint-disable-next-line no-shadow
  19. (importer) =>
  20. function customImporter() {
  21. return importer.apply(
  22. this,
  23. // eslint-disable-next-line prefer-rest-params
  24. Array.from(arguments).map((arg, i) =>
  25. i === 1 && arg === 'stdin' ? resourcePath : arg
  26. )
  27. );
  28. }
  29. );
  30. }
  31. module.exports = proxyCustomImporters;