proxyCustomImporters.js 1.0 KB

1234567891011121314151617181920212223242526272829
  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((importer) => {
  18. return function (url, prev, done) {
  19. return importer.apply(
  20. this, // eslint-disable-line no-invalid-this
  21. Array.from(arguments)
  22. .map((arg, i) => i === 1 && arg === "stdin" ? resourcePath : arg)
  23. );
  24. };
  25. });
  26. }
  27. module.exports = proxyCustomImporters;