UNPKG

3.46 kBMarkdownView Raw
1# less-plugin-sass2less
2
3[![Build Status](https://travis-ci.org/mediafreakch/less-plugin-sass2less.svg?branch=master)](https://travis-ci.org/mediafreakch/less-plugin-sass2less) [![Node version](https://img.shields.io/npm/v/less-plugin-sass2less.svg?style=flat)](https://www.npmjs.com/package/less-plugin-sass2less) [![Coverage Status](https://coveralls.io/repos/github/mediafreakch/less-plugin-sass2less/badge.svg?branch=master)](https://coveralls.io/github/mediafreakch/less-plugin-sass2less?branch=master)
4
5Want to use a UI library written in SASS, re-use it's mixins and variables but your entire source code is written in LESS? Sass2Less to the rescue! You can either use the `sass2less` command line utility included in this package or use it as a less-plugin and import `.scss` files into `.less` on-the-fly!
6
7## Get it
8
9`npm install less-plugin-sass2less --save-dev`
10
11## Usage as a less-plugin
12
13Import any `.scss` file into your existing LESS project like so:
14
15```
16// main.less
17@import (reference) "./node_modules/material-design-lite/src/material-design-lite.scss";
18
19body {
20 color: @text-color-primary; // you can now use imported SASS variables as LESS variables
21}
22
23.my-button {
24 .typo-display-4; // or use mixins from the imported SASS file
25}
26```
27
28Then simply specify it as a plugin to your less compiler:
29
30**Shell**
31
32`lessc --sass2less main.less build.css`
33
34**node.js**
35```
36let less = require('less')
37let sass2less = require('less-plugin-sass2less')
38let fs = require('fs')
39let file
40
41// get a file
42fs.readFile('main.less', 'utf-8', function(err, contents) {
43 if(err) return console.log(err)
44 file = contents
45
46 less.render(file, {
47 plugins: [sass2less]
48 }).then(function(output) {
49 console.log(output.css)
50 }, function (error) {
51 console.log(error)
52 })
53})
54```
55
56**@functions**
57
58If your sass files contains `@function` definitions and you want to use them, install `less-plugin-functions`:
59
60```
61// install additional dependency:
62npm install less-plugin-functions --save-dev
63
64// use it as a less-plugin:
65lessc --sass2less --functions main.less build.css
66```
67
68## Convert SASS files to LESS
69
70To convert all your `.scss` files at once into `.less` files, use the command line utility.
71
72`sass2less [source] destination-pattern`
73
74It supports globs, so you can do:
75
76```
77sass2less path/to/*.scss 'dist/{name}.less'
78sass2less path/to/{filea,fileb,filec}.scss 'dist/{name}.less'
79sass2less **/*.scss 'dist/{dir}/{name}.less'
80sass2less **/*.{scss,sass} 'dist/{dir}/{name}.less'
81```
82
83Available destination-pattern keys includes all the keys returned by `path.parse(filename)` (ie: root, dir, name, base, ext).
84
85## Supported conversions
86
87- `@for`
88- `@extend`
89- `@function` becomes `.function();`
90- `@if`, and `@else`
91- `@import`
92- `@include`
93- `@mixin` becomes `.mixin();`
94- `adjust-hue()`
95- `calc()`
96- `!default`
97- `!important` (for mixins)
98- `#{$foo}`
99- `nth()`
100- `rgba()`
101- `unquote()`
102- `$`
103
104There are certain things that work in both compilers and do not need explicit conversion, such as lists.
105
106## Known issues
107
108- **`@elseif` clauses** Not supported
109- **`!default` attributes** Variables with the same name will not be ignored like in SASS. The most recent takes precedence over the previous one.
110- **`@import` statements** Importing a file as `@import "file.scss"` whereas the physical file is actually named `_file.scss` is supported, but it comes at a cost. LESS errors in those files will simply result in the file not being compiled.