-
-
Notifications
You must be signed in to change notification settings - Fork 431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: pass loaderContext
to custom importer
#513
Conversation
Codecov Report
@@ Coverage Diff @@
## master #513 +/- ##
==========================================
+ Coverage 97.43% 97.45% +0.02%
==========================================
Files 6 6
Lines 117 118 +1
==========================================
+ Hits 114 115 +1
Misses 3 3
Continue to review full report at Codecov.
|
Hey @evilebottnawi, thank you for your PR 👍 Can you tell me a little bit more about the use-case of accessing the loader context in a custom importer? Usually you don't have to add files via Besides that, I don't think that we should expose the |
@jhnns use case - generate |
@jhnns i rewrite this using arguments after we accept this 😄 |
@@ -65,7 +65,7 @@ function normalizeOptions(loaderContext, content, webpackImporter) { | |||
} | |||
|
|||
// Allow passing custom importers to `node-sass`. Accepts `Function` or an array of `Function`s. | |||
options.importer = options.importer ? proxyCustomImporters(options.importer, resourcePath) : []; | |||
options.importer = options.importer ? proxyCustomImporters(options.importer, resourcePath, loaderContext) : []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case this is lands resourcePath
&& loaderContext
should be merged here, since resourcePath
is already on the loaderContext
There was almost the same feature request at the less-loader. Does the approach with nodemon I mentioned here work for you as well? |
@jhnns |
This would also make possible to use for example Are you planning to add this feature? |
/cc @jhnns |
@jhnns @michael-ciniawsky Really just a friendly ping, are you planning to add this feature? Is there anything I can contribute to get it merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is needed to some point and gives users the flexibility they often want and need, ideally it would be the passed as the second argument and passing the resourcePath
separately is being removed, but that's a breaking change so maybe better to do it in a follow up PR
Codecov Report
@@ Coverage Diff @@
## master #513 +/- ##
==========================================
+ Coverage 97.43% 97.45% +0.02%
==========================================
Files 6 6
Lines 117 118 +1
==========================================
+ Hits 114 115 +1
Misses 3 3
Continue to review full report at Codecov.
|
I'm still not convinced to add this feature. The custom importer API belongs to Sass and it doesn't feel right to extend it. A custom importer should not read several files to generate the source code. Ideally, it would just convert the given source code into Sass compatible code. Can you explain me your use-case? @evilebottnawi You've mentioned the @bencergazda Why do you need to use |
@jhnns I have a custom importer, which works as a part of a simple Sass/JS plugin-system – the importer checks all the candidate plugin paths and resolves with the array of the available file paths. It seems ideal to check the file path(s) with webpack's resolve algorithm, just how it would be done otherwise in case of a normal I have also tried webpack's Using the loader's (It was anyway an interesting discovery that I could get rid of the threadpool issue by using the |
@bencergazda Your use case should also be solvable via webpack's resolver (either via the |
Maybe I've missed it in the course of the conversation, but was there ever a solution mentioned for indicating to webpack that a certain file should be watched? I have a custom sass importer that's able to import svg files as sass modules, which works fine — the problem is that I can't indicate to webpack that the svg file is one that it should watch, and, if it changes, rebuild the entire config. From what I know, the @jhnns Would love this feature added, or if not, some other kind of workaround. Should I just try to write a regular webpack loader? |
@matt-curtis Let's be solved for the next release, ETA is the next week, right now, you can write manual loader if you need this ASAP |
Looking forward to it. Thanks! |
In some case i need use
addDependency
oraddContextDependency
(or other useful api stuff), be great have ability to this. If you accept this i will write tests for this, thank you!