Brackets-SASS Plugin setup

  • 21
Brackets is a cool , superb and free IDE with a ton of useful plugins! One such is the Brackets SASS plugin.

On a personal laptop, its a straight forward stuff. Go to the Install extensions, search for Brackets SASS, Click install. But from a proxy, we will be forced to do the Manual Installation most times.
Once installed, we need Brackets to auto compile the required sass files and provide the css output at a folder we want.



If we click install, it might show an Installation failed error.

Go to this site and download the below zip. (first one )

Once downloaded, drag and drop the same into the "Drag zip here or Install from URL" button.


Then go to Debug tab > Reload With extensions.

To configure the same, go to here.
Copy the below section from that site.

Once done, Create a " .brackets.json"  at the root of the project: ( Dont forget the dot in front )


Copy paste the thing which we have copied before into this .brackets.json custom file which we have created and placed in the root.

Here is the code version for copy pasting:
{
    "sass.enabled": false,
    "sass.compiler": "libsass",
    "path": {
        "scss/styles.scss": {
            "sass.enabled": true, 
            "sass.options": {                
                "outputDir": "../css/",
                "imagePath": null,
                "sourceComments": false,
                "outputStyle": "nested"
            },
            "linting.collapsed": true
        }
    }
}


What we say here basically is:
Take the styles.scss file inside the scss folder for auto compiling. Let the output be placed inside the css folder which is one level back, on the same level as scss folder. Let the output css style be nested.
There are a lot more options configurable, kindly check the link for full options.

Restart brackets. And so a Reload with Extensions from Debug tab above ( just in case! )
Listen: Sometimes, we may not see the same getting complied first, Dont panic!
Just go to styles.scss once and simply press a space and save once more to trigger the compiling externally. At times, Brackets behave strangely, refusing to compile the same as and when we write something. Run the index file now.


Damn! It worked. 
No this is the most simple and straight forward stuff. In a real project, we might be having a lot of nesting structures for our sass folders.

Nesting:

A sample workflow will be having a partial folder inside of which i will be creating variables.scss, mixins.scss, extend.scss, module specific or functionality specific scss files and then importing them together in one styles.scss file which is complied to get the corresponding css file.

One such folder structure is shown above. We have a partials folder inside of which we have a "_variables.scss" folder holding all variables, colors, font sizes, padding, margin, url paths etc.

In our styles.scss, we have imported the same first.
Run the same and we get the same output as we got last time, but this time, we have created partial files. Keep adding partial files as needed, just that dont forget to import them in the styles.scss file.

Go to the ".brackets.json " file, change the "outputStyle" to "compressed" for a minified css output.
That will be handy if we are having a production version of the styles with a smaller footprint than its development version.

BOOTSRAP'S SASS INTEGRATION: 

Plugin: Bootstrap-sass
I thought since everything was already done as far as proxy was concerned (which we looked at the previous post here), it was a straight one line command to install. But not as i expected. I was still being played around by the damn proxy.

I tried running the -   npm install bootstrap-sass command. But it throwed some freaky certificate issue.



Went around searching stackoverflow again :
Try these steps first.


Try running the first command and then the npm install bootstrap-sass command.
Else try the second one and repeat the same trial.

If not once, then it will work on third attempt! Thats what legend says. Try the next command.



NB: make sure, we navigate to the scss folder first before installing the bootstrap sass. ( I want it inside the sass folder, just a personal preference, not a mandate )


Dibly dobly doooo!! Hail God...Finally it got installed... I was about to go for lunch, and my appetite had gone off once i saw the same installed without errors!

Take a look at the folder structure.

See a node_modules folder created inside scss? An inside that, our bootstrap-sass folder? Thats what we want!
In our styles.scss, we first include the bootstrap import, followed by our partial:

@import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";
@import "partials/variables";  

html{
    height:100%;    
}

body{
    min-height:100%;
    background-color:$bg-main;
    color: $fg-color;
}   
.red{
    min-height:50px;
    background-color: $red;
}


Added in _variables.scss
$bg-main: #004C70;//color
$fg-color: #ffffff; 
$red: #b90b10;


And in our index.html, add the "red" class .
<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="css/styles.css" />
</head>
<body>
    
    <div class="container-fluid">
        <div class="col-md-3 red">.col-md-1</div>
        <div class="col-md-3 red">.col-md-1</div>
        <div class="col-md-3 red">.col-md-1</div>
        <div class="col-md-3 red">.col-md-1</div>
    </div>
    
</body>
</html>


Now run the index.html,


Bootstrap is up and running! Maaaaaaaan! ...





21 comments:

  1. This is awesome! Just what I was looking for. Thank you!!

    ReplyDelete
  2. "I tried running the - npm install bootstrap-sass command. But it throwed some freaky certificate issue."

    You need to open the console as an administrator, to be able to modify the Program Files.

    ReplyDelete
  3. Unknown, thanks for the pointer, i was under a proxy, and also, we wont be given admin right previleges inside office most times.

    ReplyDelete
  4. Thanks Harikrishnan, nice article and instructions. Realtime compilation of sass files makes Brackets an easy tool.

    ReplyDelete
  5. I have made all steps, but i dont have success. Do i need install ruby or something to make it working? I save the scss file, and nothing happens to css. Ty.

    ReplyDelete
    Replies
    1. Jesus, is there any error in console? Yes, the ruby gem is needed in one of the steps where we put strict-ssl to false.

      Delete
  6. Hey thank you for this article. this is so helpful. I have a question, so the css compiles into the scss folder instead of its own css folder when I run it. What did I do wrong?

    ReplyDelete
    Replies
    1. Amber, inside the .brackets.json , there is an option to set the outputDir path. Did u try changing that and see if that works?

      Delete
  7. Not working for me.I have tried everything but not compiled any .css and .css.map file. Please help me out.

    ReplyDelete
  8. Do you have any error? Or is it just that it doesnt compile anything? The post is almost one n half yrs old, and I am currently working on an environment where I have full admin rights, so i cant reproduce this scenario. I can suggest a shortcut, where in, if you have a laptop / pc where you go ahead with full installation, go to the local path where the plugin is installed, copy the folder as such, and try pushing to git / dropbox or any online repo, and from there, pull the same onto ur pc with restricted admin rights. :Paste the folder , restart the brackets, and that should be it. Now, the defacto IDE used are VS Code / Atom / Sublime Text 3 if its free, and Webstorm if its paid. So i had migrated from Brackets to other IDEs too.

    ReplyDelete
  9. Hi, I followed this steps but to no avail. There is no compilation in css file but I got error message in brackets:

    Error: `libsass` bindings not found in C:\Users\Jurek\AppData\Roaming\Brackets\extensions\user\jasonsanjose.brackets-sass\node\2.0.3\node_modules\node-sass\vendor\win32-ia32-48\binding.node. Try reinstalling `node-sass`? at Object.sass.getBinaryPath (C:\Users\Jurek\AppData\Roaming\Brackets\extensions\user\jasonsanjose.brackets-sass\node\2.0.3\node_modules\node-sass\lib\extensions.js:148:11) at Object. (C:\Users\Jurek\AppData\Roaming\Brackets\extensions\user\jasonsanjose.brackets-sass\node\2.0.3\node_modules\node-sass\lib\index.js:16:36) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object. (C:\Users\Jurek\AppData\Roaming\Brackets\extensions\user\jasonsanjose.brackets-sass\node\2.0.3\render.js:39:12)

    Maybe someone of you knows how to solve this.

    I would be very grateful for help.

    ReplyDelete
  10. mai ek doctor hu jaise ajj kal ke larkiyo or mahilao me josh kaam hone ki problem aati hai na usi problem ke lia mai kaafi saare medicin suggest kia

    mahilao ko josh ki goli ka naam
    ajj kal ki relationship jyada din nahi chal paati hai agar aap vi aise samashyao se agar presaan ho to iske sollution ke lia bhut saari dawaiya market me hai

    ReplyDelete