@@ -6,8 +6,9 @@ import { getOptions } from 'loader-utils';
66import validateOptions from 'schema-utils' ;
77
88import schema from './options.json' ;
9- import processResult from './processResult' ;
109import getLessOptions from './getLessOptions' ;
10+ import removeSourceMappingUrl from './removeSourceMappingUrl' ;
11+ import formatLessError from './formatLessError' ;
1112
1213const render = promisify ( less . render . bind ( less ) ) ;
1314
@@ -22,7 +23,25 @@ function lessLoader(source) {
2223 const callback = this . async ( ) ;
2324 const lessOptions = getLessOptions ( this , options , source ) ;
2425
25- processResult ( this , render ( lessOptions . data , lessOptions ) , callback ) ;
26+ render ( lessOptions . data , lessOptions )
27+ . then ( ( { css, map, imports } ) => {
28+ imports . forEach ( this . addDependency , this ) ;
29+
30+ // Removing the sourceMappingURL comment.
31+ // See removeSourceMappingUrl.js for the reasoning behind this.
32+ callback (
33+ null ,
34+ removeSourceMappingUrl ( css ) ,
35+ typeof map === 'string' ? JSON . parse ( map ) : map
36+ ) ;
37+ } )
38+ . catch ( ( lessError ) => {
39+ if ( lessError . filename ) {
40+ this . addDependency ( lessError . filename ) ;
41+ }
42+
43+ callback ( formatLessError ( lessError ) ) ;
44+ } ) ;
2645}
2746
2847export default lessLoader ;
0 commit comments