6.0.0 • Published 3 years ago

postcss-less v6.0.0

Weekly downloads
2,335,828
License
MIT
Repository
github
Last release
3 years ago

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)

@violetx/stylelint-config@hovey/stylelint-config-basic@xverse/matrix-code-generatorreact-scripts-jackpoodle-xiaokyorkfe-lint@astel/test@avid-ui/test@dite/bundler-webpack@infinitebrahmanuniverse/nolb-postcss-l@everything-registry/sub-chunk-2460@rife/lint@sacc/stylelint-configwd-fe-stylelint-configvue-less-formatwrc-iconwx-buildx-mpaas-to-uniappst-tssstarfiretestaaaavite-plugin-css-auto-importvscode-lintvtheme-loaderux-boxux-box-minvite-plugin-stylename-auto-classnamevue-css-format@cocoy/esp-config@ctsx/webpack@cssc-ment/configs@condorhero/stylelint-config-less@cyzeal/lint-config-lib@denaro-config/stylelint-less@demian96/tpl-build@cqfe/stylelint-config@doremijs/stylelint-config@peter-popluhar/stylelint-reusable-config@pospal/prettier-config@pospal/stylelint-configjodit-prkixbrl-viewerkestcommon_webpackfengwuxp_common_webpackdfeuk-frontenddfeuk-frontend-manualjoyer-clistylelint-config-cp-mobilestylelint-config-craglintstylelint-config-hhstylelint-config-htmlacademystylelint-config-gofundstylelint-config-moxiostylelint-config-nekostylelint-config-akrcstylelint-config-alistylelint-config-ygxystylelint-config-wikimediastylelint-config-sissstylelint-config-smartstylelint-config-taqustylelint-config-smartsstylelint-config-speedstylelint-config-recommended-lessstylelint-config-rivestylelint-no-pxsortiertyped-less-modules-tsu-webant-merge-lessumi-plugin-css-modulesumi-plugin-better-themeumi-theme-generatortouchui-packtouchui-pc-packtopology-byfetin-react-components@aipmorg/lint@antmjs/stylelint@aplus-frontend/stylelint-config@aoviz/lint@argo-design/argo-lint@applint/spec@ant-design/codemod-v5@astel/ui@aurorafe/stylelint-config-base@arietta-studio/lint@avsb/utils@astql/css.postcss@agro-expo/rules@agro-tech/rules@akijoey/stylelint-config@alsc-sfe/builder-saas-spa@aliyun-obv/obviz-cli@aliyun-obv/obviz-core@alicloud/console-toolkit-plugin-react@baic/stylelint-config-yolk@baic/yolk-cli@beilo/modern@ayahub/lint
6.0.0

3 years ago

5.0.0

4 years ago

4.0.1

4 years ago

4.0.0

5 years ago

3.1.4

6 years ago

3.1.3

6 years ago

3.1.2

6 years ago

3.1.1

6 years ago

3.1.0

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.0.0

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.16.1

8 years ago

0.16.0

8 years ago

0.15.0

9 years ago

0.14.0

9 years ago

0.13.0

9 years ago

0.12.0

9 years ago

0.11.1

9 years ago

0.11.0

9 years ago

0.10.0

9 years ago

0.9.0

9 years ago

0.8.0

9 years ago

0.7.0

9 years ago

0.6.0

9 years ago

0.5.0

9 years ago

0.4.0

9 years ago

0.3.0

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago