-
Notifications
You must be signed in to change notification settings - Fork 357
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
JS API: Support custom importers #9
Comments
Is this also necessary for using it in Dart projects without |
|
Some notes on the (largely undocumented) behavior of node-sass's importer API:
The final bullet point means we probably can't model node-sass importers the same way we do the Dart API importers introduced in #179. We'll likely need to give the internal |
This allows us to support asynchronous importers and, eventually, functions without breaking synchronous support. The copies were made manually, but the eventual plan is to auto-generate the synchronous versions by stripping all asynchrony from the async versions. See #9
This allows us to support asynchronous importers and, eventually, functions without breaking synchronous support. The copies were made manually, but the eventual plan is to auto-generate the synchronous versions by stripping all asynchrony from the async versions. See #9
This allows us to support asynchronous importers and, eventually, functions without breaking synchronous support. The copies were made manually, but the eventual plan is to auto-generate the synchronous versions by stripping all asynchrony from the async versions. See #9
This allows us to support asynchronous importers and, eventually, functions without breaking synchronous support. The copies were made manually, but the eventual plan is to auto-generate the synchronous versions by stripping all asynchrony from the async versions. See #9
In node-sass, when importer function callback is invoked with @import "bootstrap"; Becomes: @import url("E:\myproject\node_modules\bootstrap\dist\css\bootstrap.css"); When using my custom importer / resolver: importer: (request, source, done) => {
// request: bootstrap
// source: E:\myproject\client\css\index.scss
this.sassImport(source, request).then(result => {
// result: E:\myproject\node_modules\bootstrap\dist\css\bootstrap.css
done({
file: result
});
}).catch(error => {
done(error);
});
} When using
Is this by-design? Also, is it possible to use importer with the sync API? |
@ryanelian I wasn't aware of that aspect of Node Sass's importer support, but it's not something I think we should support. An importer shouldn't be able to transform a dynamic import into a static import. So I guess the answer is yes, the current behavior is by design.
Yes, as long as you return the result rather than passing it to the |
I don't agree with this stance. I mean, what's the point of enabling consumers to use *CUSTOM* importer if they can't fully customize the result of the import? I'd be happy if you can just pass-through the result... 😕
Ah. That should be documented somewhere. Good to know, thanks. |
An import that loads a Sass file is a fundamentally different construct than an import that compiles to CSS. They operate at different times and do different things. They're so different that we're planning to change the name of "load a Sass file" to |
Interesting. I'm trying to understand this statement. Please correct me if I'm wrong. So in future Sass,
|
That's not exactly accurate. |
Should probably just remove them when (Make Sass ignore |
We can't just break backwards-compatibility for such a fundamental part of the language. |
Then how are you planning to support import semantics such as:? @import "bootstrap"; It is a common practice (I did not invent this) to do that, then having whatever bundler you use (PostCSS, webpack, etc.) to read
Once again, I'd be happy if you can just pass through the: @import url("node_modules/bootstrap/dist/css/bootstrap.css") |
If you want to ensure that an
You can use any of these to pass the import through for postprocessing. |
This won't be practical for above example, because you'd make people write:
While this can be practical "hey guys, unlike other standard CSS bundlers import syntax, in Sass you need to wrap library imports using That's not really a convincing pitch... |
Yes, that's why we're working on moving away from using the name |
The documentation should be updated to note that I'm still not clear on why dart sass is not calling importers for When are importers actually called? |
If Dart Sass's JS API behaves differently than Node Sass's, that's a bug. Please file an issue for it, along with a minimal JS reproduction and an explanation of how the behavior differs.
Dart Sass should call importers for both of those importers.
When the interpreter reaches an |
@nex3 Ok, makes sense. I'll file a ticket with an example. |
Greetings, Here's a reference from the official API: |
The command-line interface is shared between both the Node.js distribution and the standalone distribution. Since we can't support JS importers in the standalone distribution, we can't support them through the CLI in general. Generally speaking, if you want to use code to customize your Sass compilation, that's specifically what the JS API is for. |
Thank you very much for the quick response. I will try that approach. |
This doesn't yet support first-class function values.
We need to support the node-sass API's
importer
option, which specifies custom importers that locate and load source files. Note that this may require the use of something like synchronize.js, since Dart Sass is entirely synchronous.The text was updated successfully, but these errors were encountered: