@@ -24,20 +24,48 @@ function OptimizeCssAssetsPlugin(options) {
2424 assetProcessors : [
2525 {
2626 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 ) ;
2929 } ,
3030 }
3131 ] ,
3232 canPrint : this . options . canPrint
3333 } ) ;
3434} ;
3535
36- OptimizeCssAssetsPlugin . prototype . processCss = function ( assetName , asset ) {
36+ OptimizeCssAssetsPlugin . prototype . processCss = function ( assetName , asset , assets ) { debugger
3737 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+ }
3861 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+ } ) ;
4169} ;
4270
4371OptimizeCssAssetsPlugin . prototype . apply = function ( compiler ) {
0 commit comments