-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Support for tilde character to import from node_modules #2350
Comments
I'm not sure, though, how this helps with performance concerns. |
It is like searching a A bit of a background... |
Well, I have some concerns regarding And it seems to me that package management is something, that should be handled not by Sass, since Sass just a compiler, nothing more. Btw, for most cases it just enough to import directly from @import 'node_modules/ekzo/objects/breadcrumb'; As a benefit, it makes clear where exactly that stylesheet coming from. It will work for most cases, unless import has its own dependencies, but issue with dependencies is far beyond scope of this issue. |
As a rule, special resolution of imports are the domain of importer plugins, not the implementation itself. It's possible that this makes sense for a wrapper, such as node-sass, but not for the core language. |
When building a Sass library that will be distributed via npm, that depends on other Sass libraries that are distributed on npm, what syntax should be used for the import?
Official language support for I think this question is independent of node-sass as it's not assuming node-sass would be used for the build, just that npm will be used for the distribution. |
Eyeglass is a good solution for this. You can also just write your imports like |
As a side note, I'd probably recommend using |
I think there is merit to extending sass vocabulary.
Providing includePaths vs tilde mean different things. It is module vs
directories.
IncludePaths means anything in the directory at any level deep. Here comes
you performance concerns:- if you have an import that does not exist in any
where in the includePaths you end up visiting the entire tree for each of
the values/directories of includePaths.
~ means a module.
For node its is under node_modules.
For other platform it could mean whatever a "module or a "library" means.
If that platform does not have a concept of module they simply won't use
it.
We need to find better ways to distribute and reuse SASS. Accepting a
concept of module is a first step. And ~ character achieves that but you
could choose a different character.
…On Fri, Apr 13, 2018, 9:36 AM Serj Lavrin ***@***.***> wrote:
You can also just write your imports like ekzo/objects/breadcrumb and use
the includePaths option to ensure that your node_modules directory is on
the include path.
As a side note, I'd probably recommend using
'node_modules/ekzo/objects/breadcrumb' path instead of includePaths
option, since it makes clearer where that dependency coming from. Though,
it's just imho.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2350 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACT7OJEvsCIkW1UxaJHaZ5FKuvStaov5ks5toKnZgaJpZM4OfhBp>
.
|
But this is problematic if your peer project is hoisting dependencies |
At the moment, Sass library creators have a choice of:
At the moment, using ~ seems the most convenient approach, Eyeglass seems the most reliable approach. |
I meant that it's having same limitations with such (fortunately, quite rare) dependencies, but still a more transparent solution
Think of Eyeglass as of NPM for Node. Not exactly the same things, but a separation of concerns should be noticeable. Sass should provide the fundament for modules loading, which it does, while Eyeglass implements modules resolution. It would be strange to expect Sass implement modules resolutions technics, since it isn't tied to any particular language, and thus can't take into account all possible modules managers. |
This isn't accurate. The @penx I'm not sure what you mean by "peer project". |
Maybe a bug then because the docs says "look into". Perhaps it should say
so. Nowhere it states anything about top level. And why should it be only
top level?
```
includePaths
Type: Array<String>
Default: []
An array of paths that LibSass can look in to attempt to resolve your
@import declarations. When using data, it is recommended that you use this.
```
…On Fri, Apr 13, 2018, 5:29 PM Natalie Weizenbaum ***@***.***> wrote:
@yogeshgadge <https://github.com/yogeshgadge>
IncludePaths means anything in the directory at any level deep. Here comes
you performance concerns:- if you have an import that does not exist in any
where in the includePaths you end up visiting the entire tree for each of
the values/directories of includePaths.
This isn't accurate. The includePaths option only refers to the top level
of the path.
@penx <https://github.com/penx> I'm not sure what you mean by "peer
project".
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2350 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACT7OFFqrpHNwXA4GL0fOmkXeppvMfUKks5toRjOgaJpZM4OfhBp>
.
|
@yogeshgadge I think you're parsing that sentence slightly wrong—it says "paths that LibSass can look in to attempt to resolve", as in "paths that LibSass can look in in order to attempt to resolve". I think it's pretty clear that it means only the top-level directories, as that's how include paths work for most programming languages. |
Proposal
Add support for tilde character to import a module from node_modules.
Current workaround of 'includePath` makes the build inefficient when we have
e.g. in my
styles.scss
I can do the following@import '~bootstrap-sass/assets/stylesheets/bootstrap/alerts';
instead of
@import 'bootstrap-sass/assets/stylesheets/bootstrap/alerts';
and somewhere
incudePaths: ['./node_modules'']
My guess is that this inefficiency increases when we have many npm modules as dependencies since the search operation has to search inside the entire
node_modules
. Trying to improve some efficiency to narrowincludePaths
is very fragile because the libraries we import may import other libraries and can't be really done without trial and error or having a full knowledge of all the artifacts and their nested imports which defeats the purpose of having libraries in the first place.Side note: Some build systems have added this feature e.g. https://github.com/webpack-contrib/sass-loader. However those who do not use webpack are at loss.
The text was updated successfully, but these errors were encountered: