Skip to content
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

How to modify path resolution. #2792

Closed
justinbmeyer opened this issue Jan 29, 2016 · 3 comments
Closed

How to modify path resolution. #2792

justinbmeyer opened this issue Jan 29, 2016 · 3 comments

Comments

@justinbmeyer
Copy link

Is it possible to modify less's path resolution without making a custom build?

I work on StealJS, which supports using AMD/CJS/import to load from npm packages (and has supported LESS at least 5 years). In short, people want to be able to write:

/* ROOT/user.less */
@import "package/styles.less"

And styles.less might look like:

/* ROOT/node_modules/package/styles.less */
@import "bootstrap/less/mixins.less"

Both package and bootstrap are be located somewhere within node_modules that I'm able to locate.

My guess is that other module loaders will like this same feature (or have already figured out how to do it).

I've already written a "pre-less" transpiler that takes:

/* ROOT/user.less */
@import "package/styles.less"

And converts it to something like:

/* ROOT/user.less */
@import "./node_modules/package/styles.less"

The problem is that I can't also run my "pre-less" transpiler on styles.less. There's no hook for path resolution or when the file gets loaded. So styles.less doesn't get updated with the right path to bootstrap:

/* ROOT/node_modules/package/styles.less */
@import "../../node_modules/bootstrap/mixins.less"

TLDR;

Are there hooks for either:

  • intercepting the less source code less is loading on its own.
  • intercepting path resolution logic.

Thanks!

@matthew-dean
Copy link
Member

@justinbmeyer There's a conversation thread on #2615 that you'd probably want to read through. By the end it had gotten close to consensus, other than the keywords. Maybe you could put in your $0.02.

@matthew-dean
Copy link
Member

Specifically, @seven-phases-max objected to the word "modules" as one of the options. As neither of us are asking for the feature, maybe some suggestions could come for people who want this. Does this match your use case?

@seven-phases-max
Copy link
Member

As I understand this is exactly what #2618 is about. In summary: use https://github.com/less/less-plugin-npm-import. _Or_, considering specific `StealJS` use-case, provide your own path resolution plugin with whatever desired behavior. So merging this to #2618 (re-open if I'm wrong).

P.S. After thinking of it a bit more, I guess it's actually better to rephrase this to a simple answer (w/o even referencing all those tickets):

How to modify path resolution?

Write a plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants