postcss-less is a PostCSS syntax parser specifically designed for LessCSS. It facilitates the application of PostCSS plugins, such as Autoprefixer or Stylelint, directly to Less source code without the need for prior Less compilation. The current stable version is 6.0.0, which mandates PostCSS v8.3.5 or higher as a peer dependency and requires Node.js v12+ for execution. This library's core function is to parse Less syntax into a PostCSS Abstract Syntax Tree (AST), enabling manipulation by other PostCSS tools and subsequent stringification back into Less. It is crucial to understand that postcss-less is *not* a Less compiler; users seeking Less compilation should utilize the official Less toolchain. Releases typically align with PostCSS major version updates, often introducing breaking changes to maintain ecosystem compatibility, alongside regular bug fixes and minor feature enhancements. Its key differentiators include tight integration with the PostCSS ecosystem for Less-specific linting and transformation, and its robust ability to parse Less features like `@import` statements, inline comments, mixins, and variables into a manipulable AST.
npm install postcss-lessVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `postcss-less` with a PostCSS plugin to process LESS source code, showing a basic transformation and output.
Ensure `postcss` is installed in your project: `npm install postcss` or `yarn add postcss`.
Upgrade your Node.js environment to v12 or a newer compatible version. Tools like `nvm` (Node Version Manager) can help manage multiple Node.js versions.
Ensure your `postcss` dependency is compatible with PostCSS 8 (`^8.3.5` for `postcss-less@6.0.0`). Review your PostCSS plugin configurations for PostCSS 8 API changes, particularly around `postcss.parse()` and `processor.process()`.
If you are directly manipulating the PostCSS AST generated by `postcss-less`, you will need to update your code to reflect the new node structures. Refer to the v3.0.0 release notes for details on how specific Less constructs are now represented.
For Less compilation, use the official Less compiler (e.g., `less` npm package). `postcss-less` should be used when you want to apply PostCSS plugins to your Less source before or instead of compilation.
Always ensure there is no whitespace between a Less variable name and its colon assignment operator to avoid parsing errors.
Run `npm install postcss` or `yarn add postcss` to install the required `postcss` package.
Upgrade Node.js to v12 or higher. Use a tool like `nvm` to manage Node.js versions: `nvm install 18` and `nvm use 18`.
Ensure your `postcss` dependency aligns with the `postcss-less` requirements (e.g., `^8.3.5` for `postcss-less@6.0.0`). Update your PostCSS integration code to use `postcss([plugins]).process(css, options)` as per PostCSS 8 API.