@@ -24,20 +24,48 @@ function OptimizeCssAssetsPlugin(options) {
24
24
assetProcessors : [
25
25
{
26
26
regExp : this . options . assetNameRegExp ,
27
- processor : function ( assetName , asset ) {
28
- return self . processCss ( assetName , asset ) ;
27
+ processor : function ( assetName , asset , assets ) {
28
+ return self . processCss ( assetName , asset , assets ) ;
29
29
} ,
30
30
}
31
31
] ,
32
32
canPrint : this . options . canPrint
33
33
} ) ;
34
34
} ;
35
35
36
- OptimizeCssAssetsPlugin . prototype . processCss = function ( assetName , asset ) {
36
+ OptimizeCssAssetsPlugin . prototype . processCss = function ( assetName , asset , assets ) { debugger
37
37
var css = asset . source ( ) ;
38
+ var processOptions = Object . assign (
39
+ { from : assetName , to : assetName } ,
40
+ this . options . cssProcessorOptions || { }
41
+ ) ;
42
+ if ( processOptions . map && ! processOptions . map . prev ) {
43
+ try {
44
+ var mapJson = assets . getAsset ( assetName + '.map' ) ;
45
+ if ( mapJson ) {
46
+ var map = JSON . parse ( mapJson ) ;
47
+ if (
48
+ map &&
49
+ (
50
+ ( map . sources && map . sources . length > 0 ) ||
51
+ ( map . mappings && map . mappings . length > 0 )
52
+ )
53
+ ) {
54
+ processOptions . map . prev = mapJson ;
55
+ }
56
+ }
57
+ } catch ( err ) {
58
+ console . warn ( 'OptimizeCssAssetsPlugin.processCss() Error getting previous source map' , err ) ;
59
+ }
60
+ }
38
61
return this . options
39
- . cssProcessor . process ( css , Object . assign ( { to : assetName } , this . options . cssProcessorOptions ) )
40
- . then ( r => r . css ) ;
62
+ . cssProcessor . process ( css , processOptions )
63
+ . then ( r => {
64
+ if ( processOptions . map && r . map && r . map . toString ) {
65
+ assets . setAsset ( assetName + '.map' , r . map . toString ( ) ) ;
66
+ }
67
+ return r . css ;
68
+ } ) ;
41
69
} ;
42
70
43
71
OptimizeCssAssetsPlugin . prototype . apply = function ( compiler ) {
0 commit comments