@@ -26,7 +26,7 @@ function getLoadFilePrefix(loaderContext) {
26
26
return `-!${ require . resolve ( './stringifyLoader' ) } !${ loadersRequest } !` ;
27
27
}
28
28
29
- function loader ( src ) {
29
+ function loader ( src , prevMap , meta ) {
30
30
const { resourcePath, _compilation : compilation } = this ;
31
31
const cb = this . async ( ) ;
32
32
const fs = this . _compilation . inputFileSystem ;
@@ -51,7 +51,6 @@ function loader(src) {
51
51
} ;
52
52
53
53
const loadFile = promisify ( ( file , done ) => {
54
- // console.log('LOAD FILE');
55
54
if ( compilation [ CACHE ] . has ( file ) ) {
56
55
done ( null , compilation [ CACHE ] . get ( file ) ) ;
57
56
return ;
@@ -86,6 +85,9 @@ function loader(src) {
86
85
}
87
86
88
87
compat = compat . map ( ( [ , plugin ] ) => plugin ) ;
88
+ // spread this out now, b/c sometimes the namer runs later after the context
89
+ // is in a weird spot and it's getters don't work anymore
90
+ const namerContext = { ...this } ;
89
91
90
92
const mCssOptions = {
91
93
exportGlobals : false ,
@@ -96,10 +98,9 @@ function loader(src) {
96
98
rewrite : false ,
97
99
resolvers : [ resolver , ...( options . resolvers || [ ] ) ] ,
98
100
namer : ( filename , localName ) =>
99
- getLocalName ( filename , localName , this , options ) ,
100
- before : compat
101
- . filter ( ( p ) => p . phase === 'before' )
102
- . concat ( options . before )
101
+ getLocalName ( filename , localName , namerContext , options ) ,
102
+ before : [ options . before ]
103
+ . concat ( compat . filter ( ( p ) => p . phase === 'before' ) )
103
104
. filter ( Boolean ) ,
104
105
processing : [ ]
105
106
. concat ( compat . filter ( ( p ) => p . phase === 'processing' ) )
@@ -112,7 +113,19 @@ function loader(src) {
112
113
113
114
const processor = compilation [ PROCESSOR ] ;
114
115
115
- return processor . string ( resourcePath , src ) . then (
116
+ let root ;
117
+ if ( meta ) {
118
+ const { ast } = meta ;
119
+ if ( ast && ast . type === 'postcss' ) {
120
+ root = ast . root ;
121
+ }
122
+ }
123
+
124
+ const processing = root
125
+ ? processor . root ( resourcePath , root )
126
+ : processor . string ( resourcePath , src ) ;
127
+
128
+ return processing . then (
116
129
( { details } ) => {
117
130
const { result } = details ;
118
131
0 commit comments