less.js icon indicating copy to clipboard operation
less.js copied to clipboard

[Feature request] - Import directory

Open alexwhitman opened this issue 14 years ago • 22 comments

I've got a number of modules I'm writing styles for, one file per module, and currently I'm importing each .less file. Instead it would be useful to just able to @import 'directory_of_files/' which would include all of the less/css files in the directory.

alexwhitman avatar Jan 18 '12 15:01 alexwhitman

How do you imaginate this? This is impossible. LESS is a cliend-side javascript solution. What you are looking should be a server-side solution.

ivanovyordan avatar Jan 18 '12 16:01 ivanovyordan

LESS is both client and server, depending on preference.. I could look into this if I have time.

cloudhead avatar Jan 18 '12 16:01 cloudhead

Ordering not important?

paulogaspar7 avatar Feb 22 '12 16:02 paulogaspar7

Ordering could be an issue but in my use case I've got a 'modules' directory which has styles for different modular components (each module has a .less file) where it doesn't matter what order they get included in.

alexwhitman avatar Feb 22 '12 19:02 alexwhitman

@whitman, did you ever find the solution?

roblafeve avatar Jul 24 '12 14:07 roblafeve

@roblafeve I didn't. In the end it wasn't really an issue to just add the individual files. It could still be a useful thing though.

alexwhitman avatar Jul 24 '12 17:07 alexwhitman

I think this would break client-side functionality. The web page doesn't know what files exist on the server, hence it can't import a directory without a server-side script. Because of that, and since another solution was found, I recommend closing this issue.

matthew-dean avatar Jul 24 '12 17:07 matthew-dean

Seconded.

lukeapage avatar Jul 24 '12 22:07 lukeapage

I still think this would be a great feature server-side. "This is hard" is hardly an excuse to close it.

hypesystem avatar Jan 31 '14 10:01 hypesystem

reopened as long as it fitted into our new environment system so it would essentially give the environment a path and ask for a list of files and the browser environment could throw an error - not supported then I think this would be useful, if low priority addition.

There is another issue thats similiar knocking around too.

lukeapage avatar Jan 31 '14 13:01 lukeapage

@lukeapage Duplicate of #1181 and #1413 (or those are duplicates of this).

matthew-dean avatar Jan 31 '14 22:01 matthew-dean

Also, yes, with a proper return value of either the directory list or "not supported", this would probably be okay at that point.

matthew-dean avatar Jan 31 '14 22:01 matthew-dean

This would be extremely useful. It would also be a nice advantage over using SASS, which also doesn't have this feature.

davidcalhoun avatar Feb 07 '14 23:02 davidcalhoun

I've got to +1 this :) I can live without it but it would be a great improvement to me to have this feature. Well, that was my 2 cents !

neemzy avatar Feb 10 '14 14:02 neemzy

I now think this is something best implemented with a plugin. I'd rather see the API evolve so that the various approaches to file loading are kept out of Less.js core, which (IMHO) should really be focused on parsing.

if we were to add this to less.js core though, I think https://github.com/less/less.js/issues/1181 would be much more advantageous, since globbing patterns allow you to load directories of files, specific files, exclude files or extensions, and so on.

jonschlinkert avatar Feb 10 '14 15:02 jonschlinkert

I now think this is something best implemented with a plugin.

@jonschlinkert I'm starting to lean that way too, especially as the API / plugin stuff is gaining momentum. I'm even thinking we should consider moving anything from core to plugins that isn't cross-platform (Node/Rhino/Browser), such as data-uri.

Which of course, means this issue is still valid, it just may be addressed in a different way, yes?

matthew-dean avatar Feb 10 '14 15:02 matthew-dean

moving anything from core to plugins that isn't cross-platform (Node/Rhino/Browser)

Lol, I was thinking the opposite. If you think about it (if @lukeapage, @seven-phases-max et al had unlimited time, desire, and incentive to do so) ideally the core would be focused on code that is platform agnostic, leaving platform implementations to other "contrib" projects, e.g less-cli, less-node, less-rhino, less-browser etc, and then plugins would handle application code and edge cases. As with many other plugin-oriented tools, it would be trivial enough to init new projects with your favorite less-contrib and less user-plugins.

I'm personally in favor of this route. I can envision a time when the issues on Less.js are almost entirely related to language features, parsing, and related performance and reliability. While other libs would be created to deal with file loading, environment differences, CLI, etc.

jonschlinkert avatar Feb 10 '14 15:02 jonschlinkert

wait, I just re-read lol. you said the same thing. I read it backwards the first time... I read "isn't cross-platform" as "is cross-platform".

anyway, good stuff!

jonschlinkert avatar Feb 10 '14 15:02 jonschlinkert

^_^

I think we're all on the same page.

matthew-dean avatar Feb 10 '14 16:02 matthew-dean

Technically its easier to change less so that it asks its environment for a list of files for an import and then its up to the environment - node/browser/rhino etc to either do that, error or return what it was given.

Because of the way imports work this particular feature will be harder to do as a plugin, but yes it can be environment specific.

lukeapage avatar Feb 11 '14 06:02 lukeapage