/microsass

simple scss to css in the web navigator

Primary LanguageJavaScriptOtherNOASSERTION

Microsass GitHub license NPM version

Microsass is a script that can convert the basic structures of SCSS into CSS directly in the browser.

Microsass can process the staggered selectors of SCSS, and supports the declaration and use of basic variables, as well as the basic arithmetic processing of variables.

It also interprets the properties to add the -webkit, -moz-, -o and -ms required.


Testing and live example


Support

Microsass supports sass staggered selectors, the use of & (self selector), @media screen, @keyframes and @font-face.

Microsass allows to create variables using $size1: 300px; and basic arithmetic processes (addition, subtraction, multiplication and division)

.item {
    width: $size1 + $size2;
}

NOTE Microsass still can not interpret @media screen inside another 🙁


USE

Autoload

<head>
    <title>Microsass</title>
    <link sass="./main.scss" />
</head>
<body>
    <script src="./microsass.min.js"></script>
</body>

For multiple load you can separate using commas

<link
    sass="
    ./main.scss,
    .style.scss
"
/>

Autoload by Promise

Load by javaScript

<script src="./microsass.min.js"></script>
<script>
    microsass.import(["./main.scss", "./style.scss"]).then(() => {
        console.log("ready");
    });
</script>

Convert SCSS text

Convert micro sass string to css minify string

var scss = `
    $w1: 400px;
    $w2: 200px;
    #app {
        background: orange;
        .item{
            width: $w1 + $w2;
            p {
                color: white;
            }
        }
    }
`;
var css = microsass.convert(scss);

Convert micro sass string to css with format, html format and colors

var scss = `
    $w1: 400px;
    $w2: 200px;
    #app {
        background: orange;
        .item{
            width: $w1 + $w2;
            p {
                color: white;
            }
        }
    }
`;
var css = microsass.convert(scss, {
    format: true, // default is false
    html: true, // default is false, format is auto-set true when html is true
    color: true // default is true, only works when html is true
});

Convert by NPM module

npm install microsass -save

const microsass = require("microsass");

var css = microsass.convert(scss, {
    format: true, // default is false
    html: true, // default is false, format is auto-set true when html is true
    color: true // default is true, only works when html is true
});

Media abbreviation:

An abbreviation has been created for the media screen

Use:

@if x <= 400px {
    .item {
        width: 300px;
    }
}

Compiled output:

@media screen and (max-width: 400px) {
    .item {
        width: 300px;
    }
}

Cases:

@if x >= xx  ---->  @media screen and (min-width xx)
@if x <= xx  ---->  @media screen and (max-width xx)
@if y >= xx  ---->  @media screen and (min-height xx)
@if y <= xx  ---->  @media screen and (max-height xx)