PHPStorm: How do I combine multiple Sass files into one? - sass

I have _header.scss, _footer.scss and _main.scss and I want to combine them all into one and generate style.css.
I know it has to do with file watchers, but I haven't been able to figure out how to combine multiple files into one.

Create file styles.scss that contain this code
#import 'header';
#import 'main';
#import 'footer';

It's not a PHPStorm feature, it's a SASS feature.
In style.scss it should start out with:
#import "_header";
#import "_footer";
#import "_main";
PHPStorm doesn't have to combine the files, Scss does.

#SlawaEremkin above is correct.
Be sure that the import file is named without an underscore (not a SASS partial) otherwise there won't be an output CSS file.
Correct
styles.scss
Incorrect
_styles.scss

Related

Angular 6 style.scss not globally applied into the components

I created a new cli project with --style=sass and then defined some variables in the src/sass/styles.scss (no partials created) so they should be globally defined right? , so when i tried to use them in home.component.scss i got this error https://imgur.com/a/IckJL14
i then added a black border just to make sure normal css works and it did work , the problem is with sass ,
here's the angular.json
"styles": [
"src/sass/styles.scss",
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
"./node_modules/malihu-custom-scrollbar-
plugin/jquery.mCustomScrollbar.css",
"./node_modules/animate.css/animate.min.css",
edit: i then created a partial _variables.scss and in the component.scss i wrote #import '~sass/variables'; after importing them in the styles.scss like so #import './variables'; according to the guide from this link : https://scotch.io/tutorials/using-sass-with-the-angular-cli
still not working.
The best approach to achieve this, is creating a variable file and import this file in your scss files.
Like so:
#import "../../variables.scss";
or
#import "~variables.scss";
And in your styles.scss you just put a reference of your variable file!
If it's correct that you used the --style=sass option on project init, then that might be the problem. If you intend to use .scss files (which I would recommend), then you should have used --style=scss.
To fix this now, you can run the command ng set defaults.styleExt scss.
the answer was to simply add the full path to the component.scss like so,
#import "src/sass/~variables.scss"; instead of just #import "~variables.scss";

SASS: "Autosave" imports of partials?

Novice web dev here getting set up with SASS for the first time. Currently using Grunt to compile my css from a main SASS file.
So I have three files:
//main.css
/*some css*/
//main.scss
#import 'header';
//_header.scss
/* some sass */
When I edit and save the _header.scss file, I also have to save the main.scss file. Only then will gulp compile changes in the main.css file.
Is there a way to "autosave" every file that contains an import of a partial?
Based on what your providing I am thinking it has something to do with your main.css stuff at the top of your file. I am assuming that you have actual css below that comment in the real file?
Best practice is to #import everything at the top of the file before you do anything else.
If that is exactly what you have in the real file then it might be with how your running grunt.. Would you be able to provide your grunt config file please?

Combining scss files into one with imports

If I want to split my scss into multiple files, does every file need an import statement.
Eg if I have
_variables.scss,
Header.scss
Footer.scss
Content.scss
Will the (bottom) 3 files require imports in them (if they're using variables)
I want to have a final file eg Site.scss that merges the 3 with imports
or should the variables imports go in Site.scss too?
Every file needs an import statement, but they can all be in the root file.
Here's a great little tutorial that I've been following to make it work:
How to Structure a SASS Project
In your Site.scss file, import the _variables.scss at the top and all other files below it
#import 'variables';
#import 'Header';
#import 'Footer';
#import 'Content';
That way all other files can use the variables. You don't need to include _variables.scss in every other files.

How to compile all SASS files in a directory with Elixir?

I'm using elixir to compile my scss files.
assuming that this is my folder structure:
- app.scss
- header.scss
- footer.scss
- home/
- home1.scss
- home2.scss
For one file I can use mix.sass('app.scss'); but what if for all files in my directory without need to add them one by one?
I've tried:
mix.sass('*.scss');
mix.sass('**/*.scss');
mix.sass(['*.scss']);
mix.sass(['**/*.scss']);
and the only file I can get is the public/css/app.css
How can I compile all files in order to get something like:
- app.scss
- header.scss
- footer.scss
- home/
- home1.scss
- home2.scss
I think the wildcard solution doesn't work at all.
Have you tried to import your file dependencies, with #import "file2", and only process those files?
Assuming:
home1.scss
#import "../app"
#import "../header"
#import "../footer"
// home1 css
home2.scss
#import "./home1"
// home2 css
with:
mix.sass('home1.scss');
mix.sass('home2.scss');
you'll generate only home1.css and home2.css with the dependencies style on them.
This way you'll improve your code and get a better control from dependencies.
You can provide the file globs as an array, like this:
mix.sass(['./app.scss', './home.scss'])
Or you could import just one sass file in elixir and use the sass import directive in that file to include the rest of the files.
#import 'home.scss';
http://sass-lang.com/documentation/file.SASS_REFERENCE.html#import

Compass CSS framework - using Bootstrap with SASS

I want to use Bootstrap with SASS, but I can't find any tutorials or explanation how one can use Bootstrap with SASS. The only thing I find is installatio trough a ruby gem:
compass create my-new-project -r bootstrap-sass --using bootstrap
Which creates the following tree in my folder:
Is this enough for Bootstrap to use its own Grid, because I don't see the bootstrap.scss file, neither any Grid related files. However, I find the grid classes and all in a styles.css file. Isn't there a bootstrap.scss file that has all the mixins and everything else? And where can I find a more extended use of SASS's Bootstrap mixins, which are described here briefly:
http://www.hongkiat.com/blog/bootstrap-and-sass/
Thank You all in advance! I really can't find nothing on my problem.
(I'm using .sass files in my answer, but it should apply to .scss files, too)
Isn't there a bootstrap.scss file that has all the mixins and everything else?
Yes, there is. Here's the generated styles.sass file:
// Import Bootstrap Compass integration
#import "bootstrap-compass"
// Import custom Bootstrap variables
#import "bootstrap-variables"
// Import Bootstrap for Sass
#import "bootstrap"
bootstap_variables refers to the generated _bootstrap-variables.sass file in your project tree, whereas bootstrap-compass and bootstrap are imported from the gem's stylesheets directory.
The latter imports all other Bootstrap files, including the grid:
// Core variables and mixins
#import "bootstrap/variables";
#import "bootstrap/mixins";
// Reset and dependencies
#import "bootstrap/normalize";
#import "bootstrap/print";
#import "bootstrap/glyphicons";
// Core CSS
#import "bootstrap/scaffolding";
#import "bootstrap/type";
#import "bootstrap/code";
#import "bootstrap/grid"; # <-- here it is
...

Resources