Skip to content

Commit

Permalink
fix: file content may be undefined if .less extension is not in `@i…
Browse files Browse the repository at this point in the history
…mport`
  • Loading branch information
ccloli committed Nov 28, 2023
1 parent 23798bf commit 92bb06f
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default function (ctx: ILessLoaderContext) {
CSBFileManager.prototype.loadFile = async function (
importName,
dirname,
context,
...args
) {
// eslint-disable-next-line no-param-reassign
Expand All @@ -59,6 +60,11 @@ export default function (ctx: ILessLoaderContext) {
throw new Error('Skip resolution, it is a node_module');
}

// fix file content may be undefined if `@import` url doesn't have `.less` file extension
if (context?.ext && !filepath.endsWith(context.ext)) {
filepath += context.ext;
}

const resolvedModule = await resolveAsyncModule(filepath, ctx);
contents = resolvedModule.code;
ctx.files[filepath] = contents;
Expand All @@ -68,6 +74,7 @@ export default function (ctx: ILessLoaderContext) {
return this.loadFile(
`/node_modules/${matches[1]}`,
dirname,
context,
...args
);
}
Expand Down

0 comments on commit 92bb06f

Please sign in to comment.