-
-
Notifications
You must be signed in to change notification settings - Fork 431
Webpack sass loader does not recognize global variables file #218
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
Comments
same problem, have you found any solution? |
You need to require the file in every file you need him. |
Yes, this is the only way. It doesn't work because variables work only within This is better anyway, because now each save won't cause all Sass files to recompile, just the file you changed. |
although the problme with that is we end up with nest head fuck...:
if we restructure our directories.. BOOM! |
ran into the same problem! this is so un-convenient! |
You could perhaps set the |
I'm adding
|
Any full examples on this? I can't get this working with the examples given. |
No. I'm not given the file structure, @import statement, nor variable. This is only useful for node modules not including a global variables file like _variables.scss |
@evanjmg That's exactly what my example does—add an import for every Sass file to a file called Beyond that I'd need to know more about your setup, such as:
|
I'm using webpack 2.1.0-beta.27 and sass loader 4.1.1 doing the following: webpack.config.js
scss file in src/app/styles/partials/_variables.scss:
Importing relatively works fine, but I can't get these globals to work. |
What is |
@evanjmg Couple of things: first, although it shouldn't be an issue, since the docs say you can put the options there—I am putting them in an object called
The second thing is what I think is causing it to not work for you. The Try something like this:
|
If like me you use Vue.js with the Webpack vue-cli template, Joan Mira's blog post explains how to implement @natchiketa's solution with this stack. |
data: |
My advice: Separate your Sass files into library files and application files. This means that you have Sass files that will output CSS (your application files) and you have Sass files that provide variables and mixins for them, but don't produce any output. Then you write your application files in a modular way without implicit dependencies, but explicit ones which means that you can compile any application file and it will work without producing duplicate CSS. |
A note for webpack 2 and @natchiketa's solution:
So I had to modify my webpack config like this to have global variables:
|
@eegl your solution works for me. Thank you. |
@lorenzomigliorero's solution worked for me, except I had to go up one level to access the style folder which was inside the src folder
|
If my |
First of all thanks so much @eegl, but has anyone found a way to do this that allows your variables or mixins you're adding to have access to native sass functions i.e. or for the variable's to use a var defined int he same file, something like
|
With EEGL's solution I got variables, mixins and function work as needed. Just add data property to sass loader and specify path of the main sass config file. This way I get sass working with all of its functions. After that there is no need to import variables file in local was files. |
derp i was missing a func that was being called to get the color |
@eegl and @natchiketa solutions works for me, but in the end won't they produce huge css repetitive code? (or maybe not - I'm not sure, that's why ask - just curious about it) |
@mrmnmly if you put actual css rules into this globally imported scss file, you will end up with repetitive code. This solution only works properly for sass variables and mixins, b/c those won't directly appear in the final CSS. |
@eegl thank You for the clarification |
My webpack version is version 3.7.x. I met the same problem, and I tried all the solution mentioned above, but the problem still not solved |
Just in case, here is my webpack dev config part for SASS
|
https://github.com/webpack-contrib/sass-loader#environment-variables This link can help you. |
I have this sass directory:
//main.scss
In other js file i have:
require('./some-module-sass-file');
The problem is I have global variables in the vars file and the some-module-sass-file not recognize them and throw an error.
The text was updated successfully, but these errors were encountered: