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

support functions option, as function of loaderContext, like data`; deprecate the latter #650

Closed
lunelson opened this issue Dec 14, 2018 · 1 comment

Comments

@lunelson
Copy link
Contributor

  • Operating System: macOS Sierra
  • Node Version: 9.11.1
  • NPM Version: 6.5.0
  • webpack Version: 4.23.1
  • sass-loader Version: 7.1.0

Expected Behavior / Situation

I'd like to be able to supply a function to the functions option, which would receive the loaderContext in the same way the data option currently can do. This would allow for example configuring functions that reference the path of the .scss source file, e.g. in order to parse the size of an image file on a relative path.

Actual Behavior / Situation

Currently I can supply functions as an option but have no way of accessing the path of the .scss file being loaded, because there is no access to the loaderContext. In other scenarios where node-sass is used, the sass source file path is generally known but here it is hidden away, which significantly limits what one can do with the functions option. Instead, this mechanism is supplied to the data option but this is actually a non-standard way to inject enhanced functionality to sass--it is meant rather only for the string content of the scss source--rather the standard way is really with the functions option.

Modification Proposal

These lines in normalizeOptions.js could simply be duplicated and modified to implement the functions option in the way I've described. I'd be happy to do a PR for this; however my further suggestion, which is to deprecate the use of the data option (due to its divergence from the standard usage pattern) and offer some kind of warning about it, I'm not sure how it could be implemented

@alexander-akait
Copy link
Member

Done in #651

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

2 participants