@@ -11,7 +11,7 @@ const trailingSlash = /[/\\]$/;
11
11
// This somewhat changed in Less 3.x. Now the file name comes without the
12
12
// automatically added extension whereas the extension is passed in as `options.ext`.
13
13
// So, if the file name matches this regexp, we simply ignore the proposed extension.
14
- const isModuleName = / ^ ~ ( [ ^ / ] + | [ ^ / ] + \/ | @ [ ^ / ] + [ / ] [ ^ / ] + | @ [ ^ / ] + \/ ? | @ [ ^ / ] + [ / ] [ ^ / ] + \/ ) $ / ;
14
+ const isModuleImport = / ^ ~ ( [ ^ / ] + | [ ^ / ] + \/ | @ [ ^ / ] + [ / ] [ ^ / ] + | @ [ ^ / ] + \/ ? | @ [ ^ / ] + [ / ] [ ^ / ] + \/ ) $ / ;
15
15
16
16
// `[drive_letter]:\` + `\\[server]\[sharename]\`
17
17
const isNativeWin32Path = / ^ [ a - z A - Z ] : [ / \\ ] | ^ \\ \\ / i;
@@ -24,6 +24,7 @@ const isNativeWin32Path = /^[a-zA-Z]:[/\\]|^\\\\/i;
24
24
*/
25
25
function createWebpackLessPlugin ( loaderContext ) {
26
26
const resolve = loaderContext . getResolve ( {
27
+ conditionNames : [ 'less' , 'style' ] ,
27
28
mainFields : [ 'less' , 'style' , 'main' , '...' ] ,
28
29
mainFiles : [ 'index' , '...' ] ,
29
30
extensions : [ '.less' , '.css' ] ,
@@ -51,26 +52,17 @@ function createWebpackLessPlugin(loaderContext) {
51
52
return false ;
52
53
}
53
54
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 , '' ) ;
64
58
65
59
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
68
63
) ;
69
64
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 ] ) ] ) ;
74
66
}
75
67
76
68
resolveRequests ( context , possibleRequests ) {
@@ -97,7 +89,7 @@ function createWebpackLessPlugin(loaderContext) {
97
89
let result ;
98
90
99
91
try {
100
- if ( isModuleName . test ( filename ) ) {
92
+ if ( isModuleImport . test ( filename ) ) {
101
93
const error = new Error ( ) ;
102
94
103
95
error . type = 'Next' ;
0 commit comments