-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
@import files as modules #353
Comments
We're definitely thinking about possible ways to accomplish this. We're planning on replacing |
@nex3 Do you have a list of what needs to be supported? I'll be glad to draw up a proposal. |
Nothing really written down. There are a number of issues in the tracker that are related. Off the top of my head:
@chriseppstein Can you think of any I'm missing? |
Disabling css output should be done with a flag imho. Eg @import "file.scss" !noinclude; Non-transitive imports.. Python solves this with Namespacing.. yes. I would find it weird by default. Especially since I don't believe there's any namespacing currently in scss?
I think this would be good syntax for namespacing in general. So you could do:
so to sum it up:
-> imports file.css and file2.scss, both are compiled in.
-> translates to "native css import":
-> errors because you cannot natively import file2.scss
-> imports file.scss and file2.scss and makes all their rules available. I am not sure whether !noinclude should have to be specified for every file in the rule. I think css would not like that but then again there aren't exactly many bang-rules in css.
-> imports file.css accessible under the namespace foo, and file2.scss accessible under the namespace bar. I don't currently know whether importing a file "as another" should imply !noinclude (actual keyword name to be decided, i dont really like noinclude). I would go with "least surprise", but I can't actually figure out what behaviour would be the least surprising. I might expect importing "as" to be "obviously, I want this namespaced, so don't go compiling this for me". But then again, I might expect "I have to specify !noinclude in other cases, why not now?" non-transitive imports undefined atm. I'd recommend an |
https://github.com/import This poor guy must be getting spammed. Sorry mate. |
@adys, there're some good ideas there. I'd require the namespace to be always named in order to use namespaces. So:
...is automatically translated to "native import", while:
...are "namespaced" imports. Personally I think namespaces should be the default as one of the main purposes of preprocessors is to allow modularization. As it is we need to create fake namespaces in mixin/variable names to avoid collisions. But I understand the concern about backwards compatibility and can live with it as optional. :) I think !noinclude is unnecessary. If people want to selectively include selectors, mixins or variables, they can create a new file, import a namespace and include only what is wanted. No need for new syntax and rules. |
This doesn't make sense. You say: and then you say: It's either one or the other :P I'm comparing to python/the first example in this thread here where @import "foo" would make everything available as "foo->x". It's a bad idea imho because you could be importing foo.sass, foo.scss and foo.css in the same file. |
"I'd require the namespace to be always named in order to use namespaces" ^ This is a "let's make it fit in a compatible way" proposal. "I think namespaces should be the default" ^ This is "how I really think things should be if I was implementing SASS from scratch". That said, I don't know Ruby so I can only give ideas. :) |
@nex3 Any comments on the proposal? |
Haven't had time to look through it in-depth yet. |
It's been more than year. This isn't going to happen. Would you consider pull requests to add this feature? |
@zakdances Have patience. This is the main feature we have planned for Sass 4.0. We would like to see proposals for how this would work and get feedback on such proposals (Like @noprompt's #749). Just plowing forward and writing code without an agreement for what we are building seems likely to waste a lot of time. |
@chriseppstein Understood. Should new proposals be appended here or filed as a new issue? Did you know that each time you use I'm just surprised that functionality like Maybe I'm using |
@zakdances A gist linked to this issue would be a good way to make a proposal. Yes, I'm very aware of how |
Thank you @chriseppstein for that article link. I've been really struggling with CSS organization in larger projects lately so this is honestly helps a great deal. For anyone else reading this, there's also a |
Hi. Does this topic covers namespaced variable access? Not a few modules encourage customizing their behavior by setting global variables.
Instead of above, I wish if I could do something like..
No matter how, in the future, can I expect ways to get rid of global variables? |
If the namespace feature comes out and can have own variables, I also wish multiple instance to work, like object-oriented class and instance variable.
|
Is there an update on when import v2/Sass 4.0 will be released? Can't find a timeline or recent update anywhere online... |
Why not make the semantics of this very similar to how ES2015 module imports work? @import $grid from './grid'; //Imports everything from ./grid as $grid.
@import $utils from './utils'; //If we're namespacing you can assume no output css from these modules. So default behaviour when namespacing can be @import-once?
$grid.$settings: (
columns: 12,
gutter-width: 20px
); //Alter config variable - is this global now for anywhere the module is used (like commonjs import) or specific to the current file?
.test {
@include $grid.columns(3); //Mixin
}
.item {
@extend $utils.%clearfix; //Extend placeholder
font-size: $utils.rem(18px); //Function
}
//Could also allow import of only what you need from a module
@import ( rem, %clearfix ) from './utils';
@import ( $positive, $negative, $neutral ) from './colors';
@import ( columns ) from './grid';
//Import and rename
@import ( columns as columns2 ) from './grid2';
//Perhaps as with commonjs you can even give control over what gets exported from a file to the file itself?
//Eg. in './utils' above
//Not exported
@function map-extend($map, $maps...) {
/*...*/
}
//Exported
@export @function rem($value) {
/*...*/
}
@export %clearfix {
/*...*/
}
Just a thought, seems javascript modules semantics could fit quite well for Sass too. |
Alternatively if you don't want dot notation (Sass seems to be largely avoiding it) you could even decide that the importing an entire library under a variable eg. That would eliminate the need for a new dot-notation or some other way to access items in an imported module 'collection' - the usage of all those things could stay the same as it is currently. @import ( rem, %clearfix ) from './utils';
@import ( $positive, $negative, $neutral ) from './colors';
@import ( columns ) from './grid';
//Import and rename
@import ( columns as columns2 ) from './grid2'; Exports: //Exported
@export @function rem($value) {
/*...*/
}
@export %clearfix {
/*...*/
}
//re-export (useful for libraries/index files). Can optionally use rename syntax too
@export ( columns as grid-columns ) from './grid' The no-output use-case is also covered, since you're only importing what you need in the first place. |
4 years since 2013. 4 years you've been saying that this or this feature is going to be add to Sass 4.0. When does this incredible 4.0 version is going to be released ? Has this version been abandoned ? |
@NitroBAY yeah I'm hoping something would come out of this... was thinking about using sass import-extend, but sass import can't do 'selective' import & etc :( |
The biggest advantage of that for me is it would make the sharing of variables and mixins between files so much cleaner. Today, when I want to share a variable between 2 files, I need to put the variable in a partial and then import that partial in both files. There are cases though, when the variable logically belongs to one of the modules and putting it into external partial feels like a hack and fragments the code. It feels dirty to declare some very component specific variable in a globally shared partial, just to be able to use it in another file. |
I support @simonbuerger proposal. I was thinking about ES6-way too, and even wanted to describe proposal here, but @simonbuerger catched already whole thing. ES6 imports and exports are nice, and from all I've seen so far, seems to be the most elegant and understandable. So I definitely vote for them. I also think that For instance, if module A imports some mixins, and then you import module A in your module into If we will have The only questions remained untouched (or I missed it) seems to be CSS content of imported file. I see few options:
Also it seems that named exports remained uncovered. I think this can be done by adding name to |
Also worth mention, that this whole The whole idea with In same issue also mentioned (cite of nex3):
Issue provides solution in form of // A.scss
.foo {...}
.bar {...}
// B.scss
@use "A";
.baz { @extend .foo; } I'm not sure that it should be possible at all. It sounds like a black magic, when you extend something, which actually does not exist. I think it should be made in more transparent way. Declare in your Sass file placeholder selectors, like Then import those placeholders as Most important part here is that
One more reason why idea with If you use @use "A"; and then With imports and exports of CSS you make it explicit. Import A CSS as Now we can be explicit: @include ACSS()
.baz { @extend .foo; } // will extend A .foo
@include BCSS()
.bar { @extend .foo; } // will extend A and B .foo (because they both available)
// Now there will be a bit of slightly unusual for Sass stuff, but you can catch the idea
.baz2 { @extend ACSS.foo; } // will extend only A .foo
.bar2 { @extend BCSS.foo; } // will extend only B .foo In worst case, if we don't want to limit users to placeholders-only (this can be troublesome), we can add option to imported CSS mixin. Something like: @include ACSS({ print: false })
.baz { @extend .foo; } // will extend A .foo This won't print CSS, but will make it available as context for extension. |
Lastly, what bothers me the most: will we be able to make such large amount of For instance, even right now it is possible to encapsulate every CSS in global mixin manually (see my brief example at #739 (comment)). Just for clarity, here is how it can be done now: let's say, we add our button styles to And, in fact, it covers plenty of scenarios. It already brings encapsulation we need without the need to throw everything into the global scope, except mixin itself. However, there is a trouble with it: despite you're calling So, won't we bash into same trouble here? |
The plan is to get rid of the notion of a global namespace, and have only names from files explicit referenced with |
Closing this in favor of #1094. |
----- It is inappropriate to include political and offensive content in public code repositories. Public code repositories should be neutral spaces for collaboration and community, free from personal or political views that could alienate or discriminate against others. Political content, especially that which targets or disparages minority groups, can be harmful and divisive. It can make people feel unwelcome and unsafe, and it can create a hostile work environment. Please refrain from adding such content to public code repositories. --- sass#1 sass#2 sass#3 sass#4 sass#5 sass#6 sass#7 sass#8 sass#9 sass#10 sass#11 sass#12 sass#13 sass#14 sass#15 sass#16 sass#17 sass#18 sass#19 sass#20 sass#21 sass#22 sass#23 sass#24 sass#25 sass#26 sass#27 sass#28 sass#29 sass#30 sass#31 sass#32 sass#33 sass#34 #35 sass#36 sass#37 sass#38 sass#39 sass#40 sass#41 sass#42 sass#43 sass#44 sass#45 sass#46 sass#47 sass#48 sass#49 sass#50 sass#51 sass#52 sass#53 sass#54 sass#55 sass#56 sass#57 sass#58 sass#59 sass#60 sass#61 sass#62 sass#63 sass#64 sass#65 sass#66 sass#67 sass#68 sass#69 sass#70 sass#71 sass#72 sass#73 sass#74 sass#75 sass#76 sass#77 sass#78 sass#79 sass#80 sass#81 sass#82 sass#83 sass#84 sass#85 sass#86 sass#87 sass#88 sass#89 sass#90 sass#91 sass#92 sass#93 sass#94 sass#95 sass#96 sass#97 sass#98 sass#99 sass#100 sass#101 sass#102 sass#103 sass#104 sass#105 sass#106 sass#107 sass#108 sass#109 sass#110 sass#111 sass#112 sass#113 sass#114 sass#115 sass#116 sass#117 sass#118 sass#119 sass#120 sass#121 sass#122 sass#123 sass#124 sass#125 sass#126 sass#127 sass#128 sass#129 sass#130 sass#131 sass#132 sass#133 sass#134 sass#135 sass#136 sass#137 sass#138 sass#139 sass#140 sass#141 sass#142 sass#143 sass#144 sass#145 sass#146 sass#147 sass#148 sass#149 sass#150 sass#151 sass#152 sass#153 sass#154 sass#155 sass#156 sass#157 sass#158 sass#159 sass#160 sass#161 sass#162 sass#163 sass#164 sass#165 sass#166 sass#167 sass#168 sass#169 sass#170 sass#171 sass#172 sass#173 sass#174 sass#175 sass#176 sass#177 sass#178 sass#179 sass#180 sass#181 sass#182 sass#183 sass#184 sass#185 sass#186 sass#187 sass#188 sass#189 sass#190 sass#191 sass#192 sass#193 sass#194 sass#195 sass#196 sass#197 sass#198 sass#199 sass#200 sass#201 sass#202 sass#203 sass#204 sass#205 sass#206 sass#207 sass#208 sass#209 sass#210 sass#211 sass#212 sass#213 sass#214 sass#215 sass#216 sass#217 sass#218 sass#219 sass#220 sass#221 sass#222 sass#223 sass#224 sass#225 sass#226 sass#227 sass#228 sass#229 sass#230 sass#231 sass#232 sass#233 sass#234 sass#235 sass#236 sass#237 sass#238 sass#239 sass#240 sass#241 sass#242 sass#243 sass#244 sass#245 sass#246 sass#247 sass#248 sass#249 sass#250 sass#251 sass#252 sass#253 sass#254 sass#255 sass#256 sass#257 sass#258 sass#259 sass#260 sass#261 sass#262 sass#263 sass#264 sass#265 sass#266 sass#267 sass#268 sass#269 sass#270 sass#271 sass#272 sass#273 sass#274 sass#275 sass#276 sass#277 sass#278 sass#279 sass#280 sass#281 sass#282 sass#283 sass#284 sass#285 sass#286 sass#287 sass#288 sass#289 sass#290 sass#291 sass#292 sass#293 sass#294 sass#295 sass#296 sass#297 sass#298 sass#299 sass#300 sass#301 sass#302 sass#303 sass#304 sass#305 sass#306 sass#307 sass#308 sass#309 sass#310 sass#311 sass#312 sass#313 sass#314 sass#315 sass#316 sass#317 sass#318 sass#319 sass#320 sass#321 sass#322 sass#323 sass#324 sass#325 sass#326 sass#327 sass#328 sass#329 sass#330 sass#331 sass#332 sass#333 sass#334 sass#335 sass#336 sass#337 sass#338 sass#339 sass#340 sass#341 sass#342 sass#343 sass#344 sass#345 sass#346 sass#347 sass#348 sass#349 sass#350 sass#351 sass#352 sass#353 sass#354 sass#355 sass#356 sass#357 sass#358 sass#359 sass#360 sass#361 sass#362 sass#363 sass#364 sass#365 sass#366 sass#367 sass#368 sass#369 sass#370 sass#371 sass#372 sass#373 sass#374 sass#375 sass#376 sass#377 sass#378 sass#379 sass#380 sass#381 sass#382 sass#383 sass#384 sass#385 sass#386 sass#387 sass#388 sass#389 sass#390 sass#391 sass#392 sass#393 sass#394 sass#395 sass#396 sass#397 sass#398 sass#399 sass#400 sass#401 sass#402 sass#403 sass#404 sass#405 sass#406 sass#407 sass#408 sass#409 sass#410 sass#411 sass#412 sass#413 sass#414 sass#415 sass#416 sass#417 sass#418 sass#419 sass#420 sass#421 sass#422 sass#423 sass#424 sass#425 sass#426 sass#427 sass#428 sass#429 sass#430 sass#431 sass#432 sass#433 sass#434 sass#435 sass#436 sass#437 sass#438 sass#439 sass#440 sass#441 sass#442 sass#443 sass#444 sass#445 sass#446 sass#447 sass#448 sass#449 sass#450 sass#451 sass#452 sass#453 sass#454 sass#455 sass#456 sass#457 sass#458 sass#459 sass#460 sass#461 sass#462 sass#463 sass#464 sass#465 sass#466 sass#467 sass#468 sass#469 sass#470 sass#471 sass#472 sass#473 sass#474 sass#475 sass#476 sass#477 sass#478 sass#479 sass#480 sass#481 sass#482 sass#483 sass#484 sass#485 sass#486 sass#487 sass#488 sass#489 sass#490 sass#491 sass#492 sass#493 sass#494 sass#495 sass#496 sass#497 sass#498 sass#499 sass#500 sass#501 sass#502 sass#503 sass#504 sass#505 sass#506 sass#507 sass#508 sass#509 sass#510 sass#511 sass#512 sass#513 sass#514 sass#515 sass#516 sass#517 sass#518 sass#519 sass#520 sass#521 sass#522 sass#523 sass#524 sass#525 sass#526 sass#527 sass#528 sass#529 sass#530 sass#531 sass#532 sass#533 sass#534 sass#535 sass#536 sass#537 sass#538 sass#539 sass#540 sass#541 sass#542 sass#543 sass#544 sass#545 sass#546 sass#547 sass#548 sass#549 sass#550 sass#551 sass#552 sass#553 sass#554 sass#555 sass#556 sass#557 sass#558 sass#559 sass#560 sass#561 sass#562 sass#563 sass#564 sass#565 sass#566 sass#567 sass#568 sass#569 sass#570 sass#571 sass#572 sass#573 sass#574 sass#575 sass#576 sass#577 sass#578 sass#579 sass#580 sass#581 sass#582 sass#583 sass#584 sass#585 sass#586 sass#587 sass#588 sass#589 sass#590 sass#591 sass#592 sass#593 sass#594 sass#595 sass#596 sass#597 sass#598 sass#599 sass#600 sass#601 sass#602 sass#603 sass#604 sass#605 sass#606 sass#607 sass#608 sass#609 sass#610 sass#611 sass#612 sass#613 sass#614 sass#615 sass#616 sass#617 sass#618 sass#619 sass#620 sass#621 sass#622 sass#623 sass#624 sass#625 sass#626 sass#627 sass#628 sass#629 sass#630 sass#631 sass#632 sass#633 sass#634 sass#635 sass#636 sass#637 sass#638 sass#639 sass#640 sass#641 sass#642 sass#643 sass#644 sass#645 sass#646 sass#647 sass#648 sass#649 sass#650 sass#651 sass#652 sass#653 sass#654 sass#655 sass#656 sass#657 sass#658 sass#659 sass#660 sass#661 sass#662 sass#663 sass#664 sass#665 sass#666 sass#667 sass#668 sass#669 sass#670 sass#671 sass#672 sass#673 sass#674 sass#675 sass#676 sass#677 sass#678 sass#679 sass#680 sass#681 sass#682 sass#683 sass#684 sass#685 sass#686 sass#687 sass#688 sass#689 sass#690 sass#691 sass#692 sass#693 sass#694 sass#695 sass#696 sass#697 sass#698 sass#699 sass#700 sass#701 sass#702 sass#703 sass#704 sass#705 sass#706 sass#707 sass#708 sass#709 sass#710 sass#711 sass#712 sass#713 sass#714 sass#715 sass#716 sass#717 sass#718 sass#719 sass#720 sass#721 sass#722 sass#723 sass#724 sass#725 sass#726 sass#727 sass#728 sass#729 sass#730 sass#731 sass#732 sass#733 sass#734 sass#735 sass#736 sass#737 sass#738 sass#739 sass#740 sass#741 sass#742 sass#743 sass#744 sass#745 sass#746 sass#747 sass#748 sass#749 sass#750 sass#751 sass#752 sass#753 sass#754 sass#755 sass#756 sass#757 sass#758 sass#759 sass#760 sass#761 sass#762 sass#763 sass#764 sass#765 sass#766 sass#767 sass#768 sass#769 sass#770 sass#771 sass#772 sass#773 sass#774 sass#775 sass#776 sass#777 sass#778 sass#779 sass#780 sass#781 sass#782 sass#783 sass#784 sass#785 sass#786 sass#787 sass#788 sass#789 sass#790 sass#791 sass#792 sass#793 sass#794 sass#795 sass#796 sass#797 sass#798 sass#799 sass#800 sass#801 sass#802 sass#803 sass#804 sass#805 sass#806 sass#807 sass#808 sass#809 sass#810 sass#811 sass#812 sass#813 sass#814 sass#815 sass#816 sass#817 sass#818 sass#819 sass#820 sass#821 sass#822 sass#823 sass#824 sass#825 sass#826 sass#827 sass#828 sass#829 sass#830 sass#831 sass#832 sass#833 sass#834 sass#835 sass#836 sass#837 sass#838 sass#839 sass#840 sass#841 sass#842 sass#843 sass#844 sass#845 sass#846 sass#847 sass#848 sass#849 sass#850 sass#851 sass#852 sass#853 sass#854 sass#855 sass#856 sass#857 sass#858 sass#859 sass#860 sass#861 sass#862 sass#863 sass#864 sass#865 sass#866 sass#867 sass#868 sass#869 sass#870 sass#871 sass#872 sass#873 sass#874 sass#875 sass#876 sass#877 sass#878 sass#879 sass#880 sass#881 sass#882 sass#883 sass#884 sass#885 sass#886 sass#887 sass#888 sass#889 sass#890 sass#891 sass#892 sass#893 sass#894 sass#895 sass#896 sass#897 sass#898 sass#899 sass#900 sass#901 sass#902 sass#903 sass#904 sass#905 sass#906 sass#907 sass#908 sass#909 sass#910 sass#911 sass#912 sass#913 sass#914 sass#915 sass#916 sass#917 sass#918 sass#919 sass#920 sass#921 sass#922 sass#923 sass#924 sass#925 sass#926 sass#927 sass#928 sass#929 sass#930 sass#931 sass#932 sass#933 sass#934 sass#935 sass#936 sass#937 sass#938 sass#939 sass#940 sass#941 sass#942 sass#943 sass#944 sass#945 sass#946 sass#947 sass#948 sass#949 sass#950 sass#951 sass#952 sass#953 sass#954 sass#955 sass#956 sass#957 sass#958 sass#959 sass#960 sass#961 sass#962 sass#963 sass#964 sass#965 sass#966 sass#967 sass#968 sass#969 sass#970 sass#971 sass#972 sass#973 sass#974 sass#975 sass#976 sass#977 sass#978 sass#979 sass#980 sass#981 sass#982 sass#983 sass#984 sass#985 sass#986 sass#987 sass#988 sass#989 sass#990 sass#991 sass#992 sass#993 sass#994 sass#995 sass#996 sass#997 sass#998 sass#999
I love SASS, but there's something that always bugged me about how @import works. I'd like that files were real 'packages' (or 'modules') that, when imported, don't drop all names into the global scope -- instead, they use the import name as the namespace for the names contained in the file. This would make it a lot more modular and modern.
The idea in a nutshell:
Here, foo.scss contains a mixin bar. To use it we call 'foo.bar' -- prefixing it with the 'foo' namespace. The idea requires also to support renaming the imported package on import:
I've used the keyword 'as' from Python, but it could be something else; it doesn't matter. After imported using a custom name, we use it as:
This originated here:
http://stackoverflow.com/questions/10164995/css-preprocessor-with-modules-and-sane-scope
The text was updated successfully, but these errors were encountered: