Skip to content

Commit c78465a

Browse files
committed
refactor: 💡 minor cleaning
1 parent 5f5e07b commit c78465a

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

‎scripts/build.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import * as path from 'path';
33

44
const formats: Format[] = ['cjs', 'esm'];
55

6-
const getOutputFilename = (format: Format) => {
6+
function getOutputFilename(format: Format) {
77
switch (format) {
88
case 'esm':
99
return `${format}.mjs`;
1010
default:
1111
return `${format}.js`;
1212
}
13-
};
13+
}
1414

15-
const createBuild = () => {
15+
function createBuild() {
1616
formats.map((format) => {
1717
const outputFilename = getOutputFilename(format);
1818

@@ -36,6 +36,6 @@ const createBuild = () => {
3636
console.error(e);
3737
});
3838
});
39-
};
39+
}
4040

4141
createBuild();

‎src/index.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface LoaderOptions {
1010
}
1111

1212
/** Less-loader for esbuild */
13-
export const lessLoader = (options: Less.Options = {}, loaderOptions: LoaderOptions = {}): Plugin => {
13+
export function lessLoader(options: Less.Options = {}, loaderOptions: LoaderOptions = {}): Plugin {
1414
return {
1515
name: 'less-loader',
1616
setup: (build) => {
@@ -40,12 +40,12 @@ export const lessLoader = (options: Less.Options = {}, loaderOptions: LoaderOpti
4040
const isModule = basename.endsWith('.module.less');
4141
const loader: Loader = isModule ? 'local-css' : 'css';
4242

43-
const opts: Less.Options = {
43+
const opts: Less.Options & { relativeUrls: boolean } = {
4444
filename: args.path,
4545
relativeUrls: true,
4646
...options,
4747
paths: [...(options.paths || []), dir],
48-
} as any;
48+
};
4949

5050
try {
5151
const result = await less.render(content, opts);
@@ -64,4 +64,4 @@ export const lessLoader = (options: Less.Options = {}, loaderOptions: LoaderOpti
6464
});
6565
},
6666
};
67-
};
67+
}

‎src/less-utils.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { PartialMessage } from 'esbuild';
12
import fs from 'fs';
23
import path from 'path';
3-
import { PartialMessage } from 'esbuild';
44

55
const importRegex = /@import.*?["']([^"']+)["'].*?/;
66
const globalImportRegex = /@import.*?["']([^"']+)["'].*?/g;
@@ -9,7 +9,7 @@ const importCommentRegex = /(?:\/\*(?:[\s\S]*?)\*\/)|(\/\/(?:.*)$)/gm;
99
const extWhitelist = ['.css', '.less'];
1010

1111
/** Recursively get .less/.css imports from file */
12-
export const getLessImports = (filePath: string, paths: string[] = []): string[] => {
12+
export function getLessImports(filePath: string, paths: string[] = []): string[] {
1313
try {
1414
const dir = path.dirname(filePath);
1515
const content = fs.readFileSync(filePath).toString('utf8');
@@ -54,10 +54,10 @@ export const getLessImports = (filePath: string, paths: string[] = []): string[]
5454
} catch (e) {
5555
return [];
5656
}
57-
};
57+
}
5858

5959
/** Convert less error into esbuild error */
60-
export const convertLessError = (error: Less.RenderError): PartialMessage => {
60+
export function convertLessError(error: Less.RenderError): PartialMessage {
6161
const sourceLine = error.extract.filter((line) => line);
6262
const lineText = sourceLine.length === 3 ? sourceLine[1] : sourceLine[0];
6363

@@ -71,4 +71,4 @@ export const convertLessError = (error: Less.RenderError): PartialMessage => {
7171
lineText,
7272
},
7373
};
74-
};
74+
}

0 commit comments

Comments
 (0)