• Stars
    star
    123
  • Rank 290,145 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PostCSS Syntax for parsing LESS

postcss-less

tests cover size

A PostCSS Syntax for parsing LESS

Note: This module requires Node v6.14.4+. poscss-less is not a LESS compiler. For compiling LESS, please use the official toolset for LESS.

Install

Using npm:

npm install postcss-less --save-dev

Please consider becoming a patron if you find this module useful.

Usage

The most common use of postcss-less is for applying PostCSS transformations directly to LESS source. eg. ia theme written in LESS which uses Autoprefixer to add appropriate vendor prefixes.

const syntax = require('postcss-less');
postcss(plugins)
  .process(lessText, { syntax: syntax })
  .then(function (result) {
    result.content // LESS with transformations
});

LESS Specific Parsing

@import

Parsing of LESS-specific @import statements and options are supported.

@import (option) 'file.less';

The AST will contain an AtRule node with:

  • an import: true property
  • a filename: <String> property containing the imported filename
  • an options: <String> property containing any import options specified

Inline Comments

Parsing of single-line comments in CSS is supported.

:root {
    // Main theme color
    --color: red;
}

The AST will contain a Comment node with an inline: true property.

Mixins

Parsing of LESS mixins is supported.

.my-mixin {
  color: black;
}

The AST will contain an AtRule node with a mixin: true property.

!important

Mixins that declare !important will contain an important: true property on their respective node.

Variables

Parsing of LESS variables is supported.

@link-color: #428bca;

The AST will contain an AtRule node with a variable: true property.

Note: LESS variables are strictly parsed - a colon (:) must immediately follow a variable name.

Stringifying

To process LESS code without PostCSS transformations, custom stringifier should be provided.

const postcss = require('postcss');
const syntax = require('postcss-less');

const less = `
    // inline comment

    .container {
        .mixin-1();
        .mixin-2;
        .mixin-3 (@width: 100px) {
            width: @width;
        }
    }

    .rotation(@deg:5deg){
      .transform(rotate(@deg));
    }
`;

const result = await postcss().process(less, { syntax });

 // will contain the value of `less`
const { content } = result;

Use Cases

  • Lint LESS code with 3rd-party plugins.
  • Apply PostCSS transformations (such as Autoprefixer) directly to the LESS source code

Meta

CONTRIBUTING

LICENSE (MIT)

More Repositories

1

webpack-manifest-plugin

webpack plugin for generating asset manifests
JavaScript
1,433
star
2

jsx-email

Build emails with a delightful DX
TypeScript
924
star
3

koa-webpack

Development and Hot Reload Middleware for Koa2
JavaScript
441
star
4

webpack-plugin-serve

A Development Server in a Webpack Plugin
JavaScript
337
star
5

webpack-nano

A teensy, squeaky 🐤 clean Webpack CLI
JavaScript
237
star
6

gmail-classic

CSS for reverting Gmail to the Classic Theme
CSS
216
star
7

webpack-plugin-ramdisk

🐏 A webpack plugin for blazing fast builds on a RAM disk / drive
JavaScript
118
star
8

Gmail-Notifier-Plus

Gmail Notifier Plus
C#
89
star
9

prettier-plugin-package

An opinionated package.json formatter plugin for Prettier
JavaScript
81
star
10

mocha-chrome

☕ Run Mocha tests using headless Google Chrome
JavaScript
72
star
11

apollo-log

A logging extension for the Apollo GraphQL Server
TypeScript
66
star
12

postcss-values-parser

A CSS property value parser for PostCSS
JavaScript
58
star
13

webpack-serve

A CLI for webpack-plugin-serve, providing a premier webpack development server
JavaScript
51
star
14

loglevelnext

A modern logging library for Node.js that provides log level mapping to the console
TypeScript
38
star
15

OctoGerrit

A modern, clean, and usable theme for Gerrit
CSS
29
star
16

koa-ws

Empower your koa.js application with realtime
JavaScript
26
star
17

nanoid-cli

A tiny cli wrapper for nanoid
JavaScript
24
star
18

LiberaManifesto

A Manifesto for Open Source Software and Free Services
HTML
20
star
19

webpack-log

A logger for the Webpack ecosystem
JavaScript
18
star
20

doiuse-email

Lint HTML and CSS for email support against the `Can I email?` database.
TypeScript
14
star
21

Snarf

Snarf is an NFS server implementation written in C# with .NET 4.5.
C#
13
star
22

Brew

Brew is an open source library of interface components for ASP.NET which utilitizes jQuery and jQuery UI.
JavaScript
10
star
23

github-notifications-classic

A CSS project that restores the classic Github Notifications appearance.
CSS
9
star
24

Shellscape.Common

A .NET Library I use in a lot of my projects. Written in C#
C#
7
star
25

harmonica

A module that allows use of Node.js --harmony flags, programmatically.
JavaScript
7
star
26

webpack-hot-client

A client for enabling, and interacting with, webpack Hot Module Replacement
JavaScript
7
star
27

bundler-serve

A Platform for Bundler Development Servers
JavaScript
6
star
28

fwv

A ⚡️ crazy fast streaming ⚡️ Fixed Width Value Parser
JavaScript
5
star
29

gulp-scan

A Gulp plugin to scan a file for a particular string or expression
JavaScript
5
star
30

piilist

A list of Personally Identifiable Information keys / words / phrases used for redaction or removal
JavaScript
3
star
31

thank-you

A place for me to thank the outstanding people who support my work
3
star
32

Lumen

Everything that Start should have been.
C#
3
star
33

dot

Tools for monorepos, serverless, and more
TypeScript
2
star
34

shellscape.github.io

The codebase for shellscape.org
HTML
2
star
35

Gcal-Notifier-Plus

A Google Calendar Notifier for Windows 7
C#
2
star
36

gulp-assist

Display helpful information for your Gulp tasks
JavaScript
2
star
37

babel-plugin-async-to-plain-generator

Transform async functions into non-wrapped ES2015 generators
JavaScript
2
star
38

npm-version-tree

Fetch a dependency version tree for a package
JavaScript
2
star
39

Nubs

Fancy Tabs for the Windows Desktop
C#
1
star
40

travis-target

A Node.js module to determine the file or directory targets of a Travis CI build.
JavaScript
1
star
41

gulp-mocha-chrome

☕ Run Mocha tests using Google Chrome via Gulp
JavaScript
1
star
42

prettier-tree

Prettier directory trees
1
star
43

Rumshot

1
star
44

eslint-config-shellscape

ESLint shareable config for my projects
JavaScript
1
star
45

gulp-version-conflicts

Check for and report on module version conflicts for a package
JavaScript
1
star