rollup-plugin-less

raw JSON →
1.1.3 verified Mon Apr 27 auth: no javascript maintenance

A Rollup plugin for compiling Less files to CSS. Current stable version is 1.1.3, released in 2020. It supports inserting CSS into the DOM or writing to a file. Minimal configuration, but limited flexibility compared to alternatives like rollup-plugin-postcss. Not actively maintained; last commit was in 2021.

error Error: Cannot find module 'less'
cause Less is not installed or not found in node_modules.
fix
npm install less --save-dev
error TypeError: Cannot read properties of undefined (reading 'render')
cause Incorrect import; using require without .default in CommonJS.
fix
Use require('rollup-plugin-less').default or switch to ES import.
error Error: Plugin returned an object, but expected an object with code or map property
cause Plugin version incompatibility with Rollup 2+; the plugin's transform hook returns undefined for non-Less files.
fix
Update to the latest version or ensure include/exclude patterns are correct.
gotcha The plugin expects less to be installed as a peer dependency; if not present, it will throw a runtime error.
fix Run npm install less --save-dev alongside the plugin.
gotcha When insert is true, CSS is injected into <head> only in browser environments; it will fail in Node.js SSR contexts.
fix Use output option to write CSS to a file for SSR compatibility.
deprecated The option 'useDefault' is not supported; the plugin always uses the less default render.
fix Remove any 'useDefault' option from plugin configuration.
npm install rollup-plugin-less
yarn add rollup-plugin-less
pnpm add rollup-plugin-less

Basic Rollup config using rollup-plugin-less to compile .less files and output a CSS bundle.

// rollup.config.js
import less from 'rollup-plugin-less';

export default {
  input: 'src/main.js',
  output: {
    file: 'dist/bundle.js',
    format: 'es'
  },
  plugins: [
    less({
      insert: true,
      output: 'dist/styles.css'
    })
  ]
};