-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathless.ts
More file actions
47 lines (45 loc) · 1.09 KB
/
less.ts
File metadata and controls
47 lines (45 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* The Less preprocessor for the esbuild PostCSS Plugin.
*
* @module
*/
import type { Preprocessor, PreprocessorResults } from "./postcss.ts";
import less from "less";
/**
* Creates a Less preprocessor for the esbuild PostCSS Plugin.
*
* ```ts
* import esbuild from "esbuild";
* import { postCSSPlugin } from "@udibo/esbuild-plugin-postcss";
* import { lessPreprocessor } from "@udibo/esbuild-plugin-postcss/less";
*
* esbuild.build({
* plugins: [postCSSPlugin({
* preprocessors: [lessPreprocessor()],
* })],
* entryPoints: ["./src/index.less"],
* outdir: "./dist",
* bundle: true,
* });
* ```
*
* @param options - The options for the less preprocessor.
* @returns The less preprocessor.
*/
export function lessPreprocessor(
options?: Omit<less.Options, "filename">,
): Preprocessor {
return {
filter: /\.less$/,
async compile(
path: string,
fileContent: string,
): Promise<PreprocessorResults> {
const { css } = await less.render(fileContent, {
...options,
filename: path,
});
return { css };
},
};
}