sass-loader icon indicating copy to clipboard operation
sass-loader copied to clipboard

Add the ability to decorate the default importer

Open sgarfinkel opened this issue 3 years ago • 0 comments

Feature Proposal

I would like the ability to decorate the default importer. My primary use-case here is to dedupe global imports with a cache. I could leverage something like https://github.com/maoberlehner/node-sass-magic-importer which does this already, but then I'd lose the ability to resolve URLs with Webpack (including goodies such as aliases). Instead it would be handy to add some new functionality to decorate the default importer like this:

const importerDecorator = (importer) => {
  const resolved = new Set();
  return (url, prev, done) => {
    return importer(url, prev, ({ file }) => {
      done(resolved.has(file) ? { file: '' } : { file });
      resolved.add(file);
    });
  };
};

Feature Use Case

See above for a use-case.

Please paste the results of npx webpack-cli info here, and mention other relevant information

sgarfinkel avatar Sep 22 '22 01:09 sgarfinkel