diff --git a/src/loaders/less/index.ts b/src/loaders/less/index.ts index 389202f8..9f9013c8 100644 --- a/src/loaders/less/index.ts +++ b/src/loaders/less/index.ts @@ -1,11 +1,11 @@ import path from "path"; -import { Loader } from "../../types"; +import { Loader, LESSLoaderOptions } from "../../types"; import loadModule from "../../utils/load-module"; import importPlugin from "./import-plugin"; -const loader: Loader = { +const loader: Loader = { name: "less", test: /\.less$/i, async process({ code, map }) { @@ -14,9 +14,7 @@ const loader: Loader = { const res = await less.render(code, { ...this.options, - plugins: [importPlugin].concat( - Array.isArray(this.options.plugins) ? this.options.plugins : [], - ), + plugins: [importPlugin].concat(this.options.plugins || []), filename: this.id, sourceMap: this.sourceMap ? { outputSourceFiles: true, sourceMapBasepath: path.dirname(this.id) } diff --git a/src/types.ts b/src/types.ts index 2931cc5c..eea8e6e8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,6 +2,7 @@ import postcss from "postcss"; import cssnano from "cssnano"; import { PluginContext } from "rollup"; import { Importer as SASSImporter } from "sass"; +import { Plugin as LESSPlugin } from "less"; import { LocalByDefaultOptions } from "postcss-modules-local-by-default"; import { ExtractImportsOptions } from "postcss-modules-extract-imports"; import { ScopeOptions } from "postcss-modules-scope"; @@ -68,6 +69,15 @@ export type SASSLoaderOptions = { data?: string; }; +/** Options for Less Loader */ +export type LESSLoaderOptions = { + /** + * Array of Less plugins + * @default undefined + */ + plugins?: LESSPlugin[]; +}; + /** Options for {@link Loaders} class */ export interface LoadersOptions { /** @see {@link Options.use} */ @@ -291,7 +301,7 @@ export interface Options { | { sass?: SASSLoaderOptions & ObjectWithUnknownProps; stylus?: ObjectWithUnknownProps; - less?: ObjectWithUnknownProps; + less?: LESSLoaderOptions & ObjectWithUnknownProps; }; /** * Array of custom loaders.