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

two kind of resolver? why? #210

Closed
yeganemehr opened this issue Jun 27, 2017 · 4 comments
Closed

two kind of resolver? why? #210

yeganemehr opened this issue Jun 27, 2017 · 4 comments

Comments

@yeganemehr
Copy link

Hi

I want to know why this loader have two kind of resolver and we should adjust our codes with loader and leave less compiler mechanism? while the others (like ts-loader) have not.

I know path option and also read about advanced mechanism to resolve files.
I prepend a few lines of code to loadFile method and all type of imports (with or without ~) works fine.

loadFile(filename, currentDirectory /* , options, environment */) { // eslint-disable-line class-methods-use-this
      if(filename.substr(0, 13) == 'node_modules/'){
            filename = '~'+filename.substr(13);
      }
      const url = filename.replace(matchMalformedModuleFilename, '$1');
      const moduleRequest = loaderUtils.urlToRequest(url, url.charAt(0) === '/' ? '' : null);
      // Less is giving us trailing slashes, but the context should have no trailing slash
      const context = currentDirectory.replace(trailingSlash, '');
      let resolvedFilename;

I sure you knew you can do this but why you didn't?

@jhnns
Copy link
Member

jhnns commented Jun 27, 2017

There have been complaints that the webpack resolver is slower than the one provided by Less: #54
A recent performance test with the sass-loader indicates, that it's not the resolver which is slow, but the css-loader.

However, I decided to turn off the webpack resolver in case the paths option is set because this option makes no sense if you use the webpack resolver. This way, you can use Less the classical way or the webpack way.

I'm not sure if your example actually works. filename is a relative path that usually doesn't start with node_modules/. Maybe this example only works in your setup? Try to change that line in this repository and run the tests. The tests cover all the use-cases.

@yeganemehr
Copy link
Author

Thanks @jhnns for your reply.
I did your suggestion, forked less-loader and run tests with my changes.All passed.
Please checkout: yeganemehr/less-loader

and if It's okay to you I will create a PR.

@yeganemehr
Copy link
Author

dear @jhnns did you check this out?

@michael-ciniawsky
Copy link
Member

Feel free to open a PR for discussion about your suggested changes

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

No branches or pull requests

3 participants