-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
Is it possible to include a global config/variables file? #211
Comments
you should look into node-sass options, specifically |
Previously i was getting global variables using the jsontosass-loader and the prepend-loader to make them available to all sass files. I just refactored to use the the gist:
Then in my sass files I can access variables via |
@richard-flosi |
Yeah, I'm not sure what that would look like as a sass function, but I did consider going that route in which case I would have had to use the prepend-loader to make that available to all sass files. |
really? you can call |
I'm not a sass expert, can you give me an example of the usage you are taking about and I'll test it out? |
sure in sass:
|
yup, you are correct, that doesn't work with |
Looking for a similar thing. Would love it if there were a way of defining global imports. For instance, I have this at the head of every sass file:
Would be great to import it by default to every stylesheet. |
|
This is not true. You can do global imports just like in regular sass. Please provide a minimal test example if you think this is a bug. |
@jhnns could you show an example on how to do global imports then? I'm having this same issue. Thank you! |
the latest version of sass-loader finally lets you do this very easily. see #216 basically you need to pass the @import '_my_global_stuffs.scss'; and put that file in an inside of |
Yep. However, I don't recommend this kind of project structure. In my experience, explicit dependencies are always better than implicit ones. |
even if every single scss file in your project is guaranteed to use some file you have to import? I agree that you should keep the number of global things to a minimum, but its also silly to repeat yourself in every file of your project |
I don't think so. We all agreed that it's not good to use globals in JavaScript, why don't we adhere to the same principle in our stylesheets? It's a good thing to be explicit about the dependencies you are using. This way you always only import stuff that you are actual using. |
I agree with you @jhnns. I would prefer if I could do this somewhere in my scss files. If I have to hide it in my webpack configuration then other developers won't know it is there and won't even consider looking there I guess. Thanks! |
apparently doesn't work in the last version, I don't know if a regression or what happens. |
Yeah i'd like to know how to sort this out as well :) specially to have my mixins everywhere |
Using data and includePaths worked for me on sass-loader v. 4.1.1. While I do see the point of not using the global space there is also not enough time to make third party libraries conform to that idea. Unless there is a way to @import_once for production or otherwise prevent the style definitions from repeating themselves the idea of not using global variables at all doesn't seem feasible to me (bandwidth and time wise). But that might depend on the projects you are working on. |
anyone have a gist of their working code to share? |
As far as the discussion above about importing variables or mixins into every file, I'm finding that if I import a sass file in three different sass modules, webpack is bundling three copies of that imported file. Importing modules in this manner appears to me to be pretty detrimental. Maybe there's something I'm missing. |
A related discussion: vuejs/vue-loader#328 |
That's how Sass works by design. It's a compiler and every module is a distinct compilation. Usually, I split up my Sass modules in modules that are like libraries (they don't produce CSS code when imported) and modules that are like entry files. These are the Sass files that actually produce CSS code. |
I'm just trying to get my head around this. So, if I have one file which includes my variables / mixins: And then other components that have their own stylesheets which require the variables in So:
And they all need to reference and |
@thathurtabit yep, your should import |
Two ways:
Close. If these solutions do not suit your, please write here about this and explain why. |
I've been looking through the docs and issues but I can't seem to find anything that quite encompasses this issue.
Take the following example in "standard" SASS:
The child partial here would be able to access any variables exposed by the config file, but in
sass-loader
land, each stylesheet is treated as its own entity, meaning you can't do a global import.Is there a way to include a file to all loaded stylesheets, or is it necessary to manually import the file in every stylesheet?
The text was updated successfully, but these errors were encountered: