Stefano Vollono Stefano Vollono - 1 year ago 99
Sass (Sass) Question

How to include external libraries inside ITCSS project?

I have this structure inside my main.scss:

//******** ITCSS layers ::
//** 1. Settings – used with preprocessors and contain font, colors definitions, etc.
//** 2. Tools – globally used mixins and functions. It’s important not to output any CSS in the first 2 layers.

//** 3. Generic – reset and/or normalize styles, box-sizing definition, etc. This is the first layer which generates actual CSS.
//** 4. Elements – styling for bare HTML elements (like H1, A, etc.). These come with default styling from the browser so we can redefine them here.
//** 5. Objects – class-based selectors which define undecorated design patterns, for example media object known from OOCSS
//** 6. Components – specific UI components. This is where majority of our work takes place and our UI components are often composed of Objects and Components
//** 7. Trumps – utilities and helper classes with ability to override anything which goes before in the triangle, eg. hide helper class

// Settings
@import "settings/";

// Tools
@import "tools/tools.extend";
@import "tools/tools.mixin";

// Elements
@import "elements/";

// Components
@import "components/components.overlay";
@import "components/components.slice";
@import "components/components.text";

// Trumps
@import "trumps/trumps.utilities";

Inside my index.html, i include main.css and via bower or npm, other external libraries, like normalize, bootstrap-grid or animate.css.
What is the correct method to import other libraries? Before, after or inside main.scss? I have this doubt because It’s important not to output any CSS in the first 2 layers. Furthermore, often this files are pure css and i can't @import that inside my *.scss.


<!--build:css css/main.min.css -->
<link rel="stylesheet" href="bower_components/normalize-css/normalize.css">
<link rel="stylesheet" href="bower_components/bootstrap-v3-grid/bootstrap-v3-grid.css">
<link rel="stylesheet" href="style/css/main.css">
<!-- endbuild -->

Answer Source

I would symlink Normalize.css to a Sass file (_generic.normalize.scss) and import it into the Generic layer.

I would symlink Bootstrap to a Sass file (_objects.grid.scss) and import it into the Objects layer.

This will keep the ITCSS order true, and reduce your render-blocking CSS into just one HTTP request.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download