rollup-plugin-less-modules

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

A Rollup plugin that compiles imported LESS files into CSS during bundling. Version 0.1.11 is the latest stable release (no update in several years). Designed for component-based architectures like Angular that need style encapsulation. Alternatives include rollup-plugin-postcss or rollup-plugin-styles; this plugin is lighter but limited to LESS only and lacks modern PostCSS features. It supports source maps, minification via clean-css, and optional separate CSS output file. The repository is archived (not actively maintained).

error Error: Could not find module 'rollup-plugin-less-modules' from '...'
cause The package is not installed or is missing from node_modules.
fix
Run npm install --save-dev rollup-plugin-less-modules.
error TypeError: lessModules is not a function
cause Using require() in an ESM-only package, or incorrect import syntax.
fix
Use ES module import: import lessModules from 'rollup-plugin-less-modules';.
error Error: The `output` option is not supported in rollup-plugin-less-modules v0.1.x. Use separate output if needed.
cause Using output configuration from Rollup plugin incorrectly.
fix
Pass output as a plugin option, not in Rollup's output config.
breaking The plugin does not work with Rollup >= 2.0 due to the removal of the bundle.transform hook.
fix Use an alternative plugin like rollup-plugin-postcss.
breaking Default export changed from `lessModules` to `default` export in v0.1.0.
fix Update imports: use `import lessModules from 'rollup-plugin-less-modules';`.
deprecated The `options.sourceMap` property is deprecated; use `sourcemap` at top-level options instead.
fix Pass `sourcemap: true|false|'inline'` directly to the plugin.
gotcha Source maps may have incorrect file paths if `options.filename` is not set in Less options.
fix Set `options.filename` relative to project root.
npm install rollup-plugin-less-modules
yarn add rollup-plugin-less-modules
pnpm add rollup-plugin-less-modules

Configures Rollup to compile imported LESS files and output a separate CSS bundle with inline source maps.

import { rollup } from 'rollup';
import lessModules from 'rollup-plugin-less-modules';

rollup({
    input: 'src/index.js',
    output: {
        file: 'dist/bundle.js',
        format: 'es'
    },
    plugins: [
        lessModules({
            output: 'dist/styles.css',
            sourcemap: 'inline'
        })
    ]
});