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

Add _index.scss resolution when using @import on a directory

Open mattpilott opened this issue 6 years ago • 39 comments

I have hit a point where this would be really useful for myself and the team. Take a look at https://github.com/sass/sass/issues/690

Theres a fair bit of discussion resolving with the addition of this feature, I am wondering if this is on the radar and when it will be available.

Thanks!

mattpilott avatar Apr 20 '18 15:04 mattpilott

The support has landed in libsass with https://github.com/sass/libsass/commit/3af837c4e6053487186cfcf564a990ff11e4e356 but won't be available here till the next libsass tagged release is brought into node-sass

nschonni avatar Apr 20 '18 21:04 nschonni

Any timescales on that @nschonni ?

mattpilott avatar Apr 20 '18 21:04 mattpilott

Seconding @matt3224 here. Is there a timeline on this feature?

oqx avatar Jul 10 '18 18:07 oqx

Libsass was bumped in 4.9 https://github.com/sass/node-sass/commit/9d6faf6f0a005dc73870b1f87268014a82f170e3 so this should be available

nschonni avatar Jul 10 '18 19:07 nschonni

Actually doesn't look like it was https://github.com/sass/node-sass/blob/master/src/libsass/src/file.cpp

nschonni avatar Jul 10 '18 19:07 nschonni

It still doesn't work. :(

I've generated angular project with @angular/[email protected] and dependency that's responsible for compiling whole project(@angular-devkit/build-angular@~0.6.8) is using [email protected]. As far as I know it's also compiling all the .sass files within application.

To the point, am receving such error after attempting to import file called '_index.scss' from directory 'src/styles'.

@import './styles';
^
      File to import not found or unreadable: ./styles.
      in /Users/<user>/Projects/<name>/src/index.scss (line 2, column 1)

Chlebamaticon avatar Aug 07 '18 20:08 Chlebamaticon

Doesn't work for me too. ( And the doc says it's already there: https://sass-lang.com/documentation/file.SASS_REFERENCE.html#index_files

I invented this hack: Instead of index.scss or _index.scss I make a _.scss.

For exapmle block/_.scss

Then I import like that: @import "block/"; Everything works fine, although syntax check of my IDE is not very happy.

moraveyo avatar Oct 29 '18 17:10 moraveyo

I'm looking for this too. Just tested the current version of node-sass to see if it's updated in 4.11, but it's not yet. https://github.com/mattfelten/node-sass-index-test

mattfelten avatar Dec 19 '18 00:12 mattfelten

Just looked into this more. Looks like libsass has the change required in 3.6, but that hasn't been released yet. Looks like we're waiting for 3.6 to be released first.

https://github.com/sass/libsass/issues/2772#issuecomment-442716577 says it'll be released around Xmas, so converting from internet time, we'll have this feature by June.

mattfelten avatar Dec 19 '18 00:12 mattfelten

libsass 3.6 got released just under a week ago.

How fast can we release a new version of node-sass that uses libsass 3.6?

PolyPik avatar May 23 '19 18:05 PolyPik

It'll be a couple weeks..it's a complicated process and I'm off on vacation till the end of June.

On Fri., 24 May 2019, 4:34 am PolyPik, [email protected] wrote:

libsass 3.6 https://github.com/sass/libsass/releases/tag/3.6.0 got released just under a week ago.

How fast can we release a new version of node-sass that uses libsass 3.6?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sass/node-sass/issues/2339?email_source=notifications&email_token=AAENSWDKVVHQXRGXYBLPF43PW3PSNA5CNFSM4E3WV7XKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWDDI6Q#issuecomment-495334522, or mute the thread https://github.com/notifications/unsubscribe-auth/AAENSWBDQETGJXL7DMTKUF3PW3PSNANCNFSM4E3WV7XA .

xzyfer avatar May 23 '19 22:05 xzyfer

@mattfelten so converting from internet time, we'll have this feature by June.

June was a pretty good estimate (fingers crossed)

nottrobin avatar Jun 03 '19 10:06 nottrobin

So is this change to libsass 3.6 going to be a minor release or a major release?

PolyPik avatar Jul 09 '19 16:07 PolyPik

@xzyfer Do we have an ETA on this improvement?

PolyPik avatar Jul 12 '19 00:07 PolyPik

so the documentation https://sass-lang.com/documentation/at-rules/import#index-files lies saying it's available in "LibSass since 3.5.0"?

I'm trying to make it work with node-sass v 4.12.0 which has LibSass 3.5.5 under the hood.

fetis avatar Jul 19 '19 15:07 fetis

There seems to be a drought of commits and PRs.

PolyPik avatar Aug 05 '19 18:08 PolyPik

Any updates?

dnemoga avatar Aug 09 '19 10:08 dnemoga

I would actually like to see this thing being configurable but with a fallback to _index. That way it doesn't have to be that name and also it won't break existing setups if people can just give it a new name.

cactysman avatar Aug 22 '19 08:08 cactysman

@metaa that would be a feature request to sass/sass to change the language

nschonni avatar Aug 22 '19 18:08 nschonni

Still not in node-sass 4.13.0, either, even though the docs made me believe it would work.

payneio avatar Dec 09 '19 15:12 payneio

@payneio which docs?

saper avatar Dec 10 '19 08:12 saper

Have you tried switching to dart sass. I use this now on all projects, has index feature. npm i sass

https://www.npmjs.com/package/sass

mattpilott avatar Dec 10 '19 14:12 mattpilott

Ahh, @saper, now, I see https://sass-lang.com/documentation/at-rules/import#index-files indicates "LibSass since 3.6.0". Looking into what is packaged with node-sass, it looks like it is currently 3.5.0. I assumed if I downloaded the latest node-sass that it would work. Is there any way to get node-sass with LibSass 3.6.0?

payneio avatar Dec 12 '19 18:12 payneio

@xzyfer Indicated that it wouldn't be a quick upgrade. If someone else wants to attempt the upgrade, submit a PR.

lachieh avatar Dec 12 '19 19:12 lachieh

@mattfelten so converting from internet time, we'll have this feature by June.

June was a pretty good estimate (fingers crossed)

Turns out June was a terrible estimate

nottrobin avatar Dec 12 '19 23:12 nottrobin

you can use _.scss instead of index.scss like this @import "path/to/scss/files/" and it works

kreo avatar Feb 21 '20 23:02 kreo

Is there documentation explaining how node-sass is built? I intend to upgrade the libsass version myself if @xzyfer will not do it.

I know it involves using node-gyp to build libsass and then there are bindings that make libsass work with NodeJS.

However a more or less official explanation would still help a lot.

PolyPik avatar Mar 04 '20 17:03 PolyPik

@polypik you can build node-sass with a pre-built libsass using LIBSASS_EXT, LIBSASS_CFLAGS and LIBSASS_LDFLAGS environment variables, see example at https://github.com/saper/ports-exp/blob/06f2c7fa24091d143d603c5c86e4b8e3c3982ecf/textproc/node-sass/Makefile#L27-L29

libsass_pic.a can be built by packing object files from the src/.libs directory of libsass into one file like in this line https://github.com/saper/ports-exp/blob/06f2c7fa24091d143d603c5c86e4b8e3c3982ecf/textproc/libsass35/Makefile#L33 This is not necessary if you can live with dynamic linking with the already installed libsass.so, in that case just point to it using LIBSASS_LDFLAGS.

Alternatively, you can update the source in the node-sass directory as checked out from git in src/libsass. Make sure you have that submodule installed. npm install from there should do the job.

Before you build the binding, please update package.json "libsass" value to indicate the version of the libsass you are using, possibly with some indicator this is your change.

Of course - any problems resulting from this remain your own...

saper avatar Mar 04 '20 18:03 saper

src/libsass appears to be a subtree not a submodule. If it was a submodule, the Github website would show a different icon for that directory.

Also what branch should I make these changes to when I fork the repo? The master branch?

PolyPik avatar Mar 06 '20 18:03 PolyPik

@polypik currently v4.13.1 release tag and the master branch are almost identical as we speak,

saper avatar Mar 06 '20 18:03 saper