@@ -57,20 +57,29 @@ function insertStartMarker(nodes) {
57
57
curNode = nodes [ curIndex ] ;
58
58
}
59
59
60
+ // In case if module contains only imports we need to add at least one rule
61
+ // otherwise module will be removed and won't be able to restore imports
62
+ if ( ! curNode && requiredImports . length ) {
63
+ curNode = emptyNode . clone ( ) ;
64
+
65
+ // source required to properly output module content
66
+ curNode . source = nodes [ 0 ] . source ;
67
+
68
+ nodes . push ( curNode ) ;
69
+ }
60
70
61
71
if ( curNode ) {
62
72
curNode . reexportRequiredImports = requiredImports ;
63
73
64
74
let contentStart = postcss ( )
65
75
. process ( '.postcss-reexport[data-type="start"]{display: none;}\n' ) . root . nodes [ 0 ] ;
66
76
67
- curNode . parent . source . input
68
-
69
77
// postcss-import will look for source in first node with type="media"
70
78
contentStart . source = nodes [ 0 ] . source ;
71
79
72
80
nodes . splice ( curIndex , 0 , contentStart ) ;
73
81
hasStart = true ;
82
+
74
83
}
75
84
76
85
return hasStart ;
@@ -220,10 +229,10 @@ function extractImportedBlocksRecursive(styles, options) {
220
229
} ) ;
221
230
222
231
let offset = 0 ;
223
-
232
+
224
233
extractIndexes . forEach ( ( extracData , index ) => {
225
234
var sliceCount = extracData . end - extracData . start + 1 ;
226
-
235
+
227
236
var extractedStyles = styles . nodes
228
237
// excract previously imported block
229
238
. splice ( extracData . start - offset , sliceCount ) ;
@@ -232,7 +241,6 @@ function extractImportedBlocksRecursive(styles, options) {
232
241
extractedStyles = extractedStyles . splice ( 1 , extractedStyles . length - 2 ) ;
233
242
234
243
// TODO: better solution for wrong "\" direction
235
-
236
244
var curFile = extractedStyles [ 0 ] . source . input . file ;
237
245
var contextRelativePath = path . relative ( contextPath , path . dirname ( curFile ) ) ;
238
246
var fileName = path . basename ( curFile ) ;
0 commit comments