Skip to content

Commit

Permalink
fix(less): add plugins to less loader options type
Browse files Browse the repository at this point in the history
  • Loading branch information
Anidetrix committed Mar 24, 2020
1 parent b971fc9 commit 8b502ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/loaders/less/index.ts
Original file line number Diff line number Diff line change
@@ -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<LESSLoaderOptions> = {
name: "less",
test: /\.less$/i,
async process({ code, map }) {
Expand All @@ -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) }
Expand Down
12 changes: 11 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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} */
Expand Down Expand Up @@ -291,7 +301,7 @@ export interface Options {
| {
sass?: SASSLoaderOptions & ObjectWithUnknownProps;
stylus?: ObjectWithUnknownProps;
less?: ObjectWithUnknownProps;
less?: LESSLoaderOptions & ObjectWithUnknownProps;
};
/**
* Array of custom loaders.
Expand Down

0 comments on commit 8b502ef

Please sign in to comment.