@@ -11,7 +11,7 @@ const trailingSlash = /[/\\]$/;
1111// This somewhat changed in Less 3.x. Now the file name comes without the
1212// automatically added extension whereas the extension is passed in as `options.ext`.
1313// So, if the file name matches this regexp, we simply ignore the proposed extension.
14- const isModuleName = / ^ ~ ( [ ^ / ] + | [ ^ / ] + \/ | @ [ ^ / ] + [ / ] [ ^ / ] + | @ [ ^ / ] + \/ ? | @ [ ^ / ] + [ / ] [ ^ / ] + \/ ) $ / ;
14+ const isModuleImport = / ^ ~ ( [ ^ / ] + | [ ^ / ] + \/ | @ [ ^ / ] + [ / ] [ ^ / ] + | @ [ ^ / ] + \/ ? | @ [ ^ / ] + [ / ] [ ^ / ] + \/ ) $ / ;
1515
1616// `[drive_letter]:\` + `\\[server]\[sharename]\`
1717const isNativeWin32Path = / ^ [ a - z A - Z ] : [ / \\ ] | ^ \\ \\ / i;
@@ -24,6 +24,7 @@ const isNativeWin32Path = /^[a-zA-Z]:[/\\]|^\\\\/i;
2424 */
2525function createWebpackLessPlugin ( loaderContext ) {
2626 const resolve = loaderContext . getResolve ( {
27+ conditionNames : [ 'less' , 'style' ] ,
2728 mainFields : [ 'less' , 'style' , 'main' , '...' ] ,
2829 mainFiles : [ 'index' , '...' ] ,
2930 extensions : [ '.less' , '.css' ] ,
@@ -51,26 +52,17 @@ function createWebpackLessPlugin(loaderContext) {
5152 return false ;
5253 }
5354
54- getUrl ( filename , options ) {
55- if ( options . ext && ! isModuleName . test ( filename ) ) {
56- return this . tryAppendExtension ( filename , options . ext ) ;
57- }
58-
59- return filename ;
60- }
61-
62- async resolveFilename ( filename , currentDirectory , options ) {
63- const url = this . getUrl ( filename , options ) ;
55+ async resolveFilename ( filename , currentDirectory ) {
56+ // Less is giving us trailing slashes, but the context should have no trailing slash
57+ const context = currentDirectory . replace ( trailingSlash , '' ) ;
6458
6559 const request = urlToRequest (
66- url ,
67- url . charAt ( 0 ) === '/' ? loaderContext . rootContext : null
60+ filename ,
61+ // eslint-disable-next-line no-undefined
62+ filename . charAt ( 0 ) === '/' ? loaderContext . rootContext : undefined
6863 ) ;
6964
70- // Less is giving us trailing slashes, but the context should have no trailing slash
71- const context = currentDirectory . replace ( trailingSlash , '' ) ;
72-
73- return this . resolveRequests ( context , [ request , url ] ) ;
65+ return this . resolveRequests ( context , [ ...new Set ( [ request , filename ] ) ] ) ;
7466 }
7567
7668 resolveRequests ( context , possibleRequests ) {
@@ -97,7 +89,7 @@ function createWebpackLessPlugin(loaderContext) {
9789 let result ;
9890
9991 try {
100- if ( isModuleName . test ( filename ) ) {
92+ if ( isModuleImport . test ( filename ) ) {
10193 const error = new Error ( ) ;
10294
10395 error . type = 'Next' ;
0 commit comments