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

Provide loader context #190

Conversation

adamdicarlo
Copy link
Contributor

@jtangelder This allows an importer to really do cool stuff like evaluate other files (use webpack's resolve mechanism) and add them to the build.

@adamdicarlo
Copy link
Contributor Author

This is branched off of the change in #189.

@adamdicarlo
Copy link
Contributor Author

Oh, looks like @jhnns has been maintaining sass-loader. Got a minute for these two one-liner (the same line, no less 😁) PRs?

@jhnns
Copy link
Member

jhnns commented Nov 22, 2015

Thank you for your pull-request.

Could you add a small paragraph to the README describing the feature (e.g. with a use-case)?

@adamdicarlo adamdicarlo force-pushed the provide-loader-context branch from 4d54c0d to 569bb4d Compare November 25, 2015 01:49
This allows importers to resolve import paths using Webpack's API and
add dependencies to the build.
@adamdicarlo adamdicarlo force-pushed the provide-loader-context branch from 569bb4d to a2045ce Compare November 25, 2015 01:53
@adamdicarlo
Copy link
Contributor Author

Here we go! It's... definitely an involved process. You asked for it... 😁 I'm not 100% sure the resolving logic is perfect but it's worked with all the cases I've thrown at it so far.

@adamdicarlo
Copy link
Contributor Author

NB: There's an "as of 3.1.3" comment in the text, based on the assumption this would be included in the next release.

@adamdicarlo
Copy link
Contributor Author

Rewrote it the documentation but I noticed a thing or two in sass-loader's path resolution logic that is different than mine (I need to path.normalize and use charAt(0), right?). And I realized it would be ideal to decouple the resolution from the actual processing. Hmmm. But you'd need to specify whether you want Sass-like (foo => _foo, foo.scss, etc.) logic for your importer, I guess.

@jhnns
Copy link
Member

jhnns commented Nov 30, 2015

We could publish sass-loader's internal functions to the context so that you can use the same functions.

@adamdicarlo
Copy link
Contributor Author

I like the way you think. Gonna let that ruminate in my brain a bit...

@jhnns
Copy link
Member

jhnns commented Mar 3, 2016

Mhmm I'm not sure about this feature anymore. It provides access to an API where things might break easily. I don't want to make a major version bump when I'm refactoring internal functions.

@adamdicarlo
Copy link
Contributor Author

I'm also not sure anymore about the thing I was using this feature for. It was a way to try to get some of the benefits of styles-in-JS via Sass, and it's a pain in a lot of ways.

@adamdicarlo adamdicarlo closed this Mar 4, 2016
@beauroberts
Copy link

Apologies for beating what's probably a very dead horse here, but I think this would be great. I've got a copy of @adamdicarlo's branch and an importer that uses the loadModule function on the loader context to import files into Sass using webpack. In combination with theo, this lets me share JSON design properties files between javascript and sass without any intermediate compilation steps, so I can write something like:

import colors from 'theo?./colors.json'

in javascript, and in sass

@import 'theo?format=scss!./colors.json'

Even if this never goes anywhere, thanks for the inspiration @adamdicarlo! And for maintaining a great tool, @jhnns

@jhnns
Copy link
Member

jhnns commented Apr 8, 2016

Thx for pointing out theo. It looks very interesting (although I'm a little disappointed that it's a gulp plugin – it could also be just a small module without gulp dependency).

I totally see the benefit. Maybe we could provide the loaderContext to the custom importer, so that you can write your own logic...

@beauroberts
Copy link

@jhnns funny you should mention - theo-loader coming soon! just trying to get it through legal. meeting with them today

@beauroberts
Copy link

In case it's useful! https://www.npmjs.com/package/theo-loader

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

Successfully merging this pull request may close these issues.

3 participants