Code Monkey home page Code Monkey logo

gulp-sass-extend-shorthand's Introduction

gulp-sass-extend-shorthand

A gulp-replace wrapper to add a syntactic sugar shorthand syntax for writing @extend at-rules in Sass. (Note, this currently only works with the SCSS syntax).

Using with Utility Class Frameworks

Using semantic class names like article-list provides much more human-readable landmarks when examining HTML than adding a string of utility classes like px-px pt-5 pb-4 absolute top-0 left-0 directly to elements in the DOM.

Instead, developers can use semantic class names in markup and then use SCSS @extend at-rules to apply utility classes to those semantic classes. If the utility class framework is converted from using true class class selected (e.g. .absolute {...}) to using placeholder selectors (e.g. %absolute {...}), Sass will automatically ignore any unused utility classes when compiling.

This plugin creates a shorthand so that developers don't have to write @extend every time they reference a utility class within a semantic selector, potentially reducing the amount of code that needs to be written by over half.

Syntax

Basic Syntax

// shorthand
.myClass {
  .myMixin;
}
// is expanded to
.myClass {
  @extend .myMixin;
}

Placeholder Mixins

// shorthand
.myClass {
  %myPlaceholderMixin;
}
// is expanded to
.myClass {
  @extend %myPlaceholderMixin;
}

Inline List Syntax

// shorthand
.myClass {
  .mixinA, .mixinB, .mixinC;
}
// is expanded to
.myClass {
  @extend .mixinA;
  @extend .mixinB;
  @extend .mixinC;
}

Stacked List Syntax

// shorthand
.myClass {
  .mixinA,
  .mixinB,
  .mixinC;
}
// is expanded to
.myClass {
  @extend .mixinA;
  @extend .mixinB;
  @extend .mixinC;
}

Using !optional

// shorthand
.myClass {
  .mixinA, .mixinB !optional;
  .mixinC;
}
// is expanded to
.myClass {
  @extend .mixinA !optional;
  @extend .mixinB !optional;
  @extend .mixinC;
}

Usage

Pipe SCSS files through gulp-sass-extend-shorthand before piping to a compiler:

const { src, dest } = require('gulp')
const sass = require('gulp-sass')
const sassExtendShorthand = require('gulp-sass-extend-shorthand')

function sassCompile() {
  return src([
    'src/scss/**/*.+(scss|css)',
    '!**/_*.*'
  ]).pipe( sassExtendShorthand() )
    .pipe( sass() )
    .pipe( dest('dist/css') )
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.