0.12.2 • Published 3 years ago

tiny-sass-compiler v0.12.2

Weekly downloads
75
License
MIT
Repository
github
Last release
3 years ago

Description

Another sass compiler written in typescript from scratch, runnable both in node and browser environment

Target

This project(Not Production Ready) is for people who want to understand how to write a compiler (almost zero dependencies) , compile steps:

  1. sourceCode (sass scanning)
  2. tokens (parsing)
  3. syntaxTree (analysis)
  4. intermediateRepresentation or IR (code generation + sourceMap)
  5. highLevelLanguage (css)

Simple demo

Online Demo

Features:

  1. Variables
  2. Nesting
  3. Extend/Inheritance
  4. Operators
  5. Mixins
  6. Modules (@import and @use(which is more efficient than @import))

Installation

npm install --save tiny-sass-compiler

Usage in node

import sass from "tiny-sass-compiler";

//render API
sass.render({filename:'./default.scss'},(err,result)=>{
  console.log(result.code)
})
// or renderSync
const result = sass.renderSync({filename:'./default.scss'})
console.log(result.code)

Usage in browser

import {compile} from  'tiny-sass-compiler/dist/tiny-sass-compiler.esm-browser.prod.js'
const result = compile(`
$font-stack:    Helvetica, sans-serif;
$primary-color: #333;

body .test{
  font: 100% $font-stack;
  color: $primary-color;
}`)

console.log(result.code)

Terminal Setup

npm install -g tiny-sass-compiler

Command Line Interface

Support .scss extension for now

Usage

tiny-sass <input> [output]

The input and output must be a directory

Example

tiny-sass src/ dist/

will generate intermediate AST file in dist/ast and css file in dist/css

Test

Snapshot Test

npm run test

will generate intermediate AST file in test-dist/ast and css file in test-dist/css

Example:

input:

$font-stack:    Helvetica, sans-serif;
$primary-color: #333;

body .test{
  font: 100% $font-stack;
  color: $primary-color;
}

output:

CSS

body .test {
    font: 100% Helvetica, sans-serif;
    color: #333;
}

Jest test

npm run jest

Interested in more intermediate status? Please view files in ./test-dist/ which contains ast after parse | transform and code after code generation

Other Readme

Reference

0.12.2

3 years ago

0.12.1

3 years ago

0.11.1

3 years ago

0.11.0

3 years ago

0.10.0

3 years ago

0.9.0

4 years ago

0.8.9

4 years ago

0.8.8

4 years ago

0.8.7

4 years ago

0.8.6

4 years ago

0.8.5

4 years ago

0.8.4

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.8.3

4 years ago

0.8.2

4 years ago

0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.3

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.3

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago