@@ -4,6 +4,8 @@ import/order,
4
4
no-shadow,
5
5
no-param-reassign
6
6
*/
7
+ import path from 'path'
8
+
7
9
import schema from './options.json' ;
8
10
import { getOptions } from 'loader-utils' ;
9
11
import validateOptions from 'schema-utils' ;
@@ -28,11 +30,6 @@ export default function loader(css, map, meta) {
28
30
// Loader Mode (Async)
29
31
const cb = this . async ( ) ;
30
32
const file = this . resourcePath ;
31
- < << << << HEAD
32
-
33
- = === ===
34
-
35
- >>> >>> > feat(plugins/import): add `@import` filter support (`options.import`) (#656)
36
33
// Loader Options
37
34
const options = Object . assign ( { } , DEFAULTS , getOptions ( this ) ) ;
38
35
@@ -70,19 +67,20 @@ export default function loader(css, map, meta) {
70
67
map = options . sourceMap
71
68
? {
72
69
prev : map || false ,
73
- inline : false ,
74
- annotation : false ,
70
+ inline : this . _module . extracted ? false : true ,
71
+ annotation : this . _module . extracted ? false : true ,
75
72
sourcesContent : true ,
76
73
}
77
74
: false ;
78
75
79
76
return postcss ( plugins )
80
77
. process ( css , {
81
- from : `/css-loader!${ file } ` ,
78
+ // `/css-loader!${file}`
79
+ from : file ,
82
80
map,
83
- to : file ,
81
+ to : this . rootContext
84
82
} )
85
- . then ( ( { root , css, map, messages } ) => {
83
+ . then ( ( { css, map, messages } ) => {
86
84
if ( meta && meta . messages ) {
87
85
messages = messages . concat ( meta . messages ) ;
88
86
}
@@ -120,31 +118,27 @@ export default function loader(css, map, meta) {
120
118
121
119
return exports ;
122
120
} , '' ) ;
123
-
124
- imports = imports ? `// CSS Imports\n${ imports } \n` : false
125
- exports = exports ? `// CSS Exports\n${ exports } \n` : false
126
- css = `// CSS\nexport default \`${ css } \``
127
121
128
122
imports = imports ? `// CSS Imports\n${ imports } \n` : false ;
129
123
exports = exports ? `// CSS Exports\n${ exports } \n` : false ;
130
124
css = `// CSS\nexport default \`${ css } \`` ;
131
125
126
+ // Mark module as CSS Module
127
+ this . _module . css = true
128
+
132
129
// TODO(michael-ciniawsky)
133
130
// triage if and add CSS runtime back
134
- < << << << HEAD
135
- const result = [ imports , exports , css ] . filter ( Boolean ) . join ( '\n' ) ;
136
-
137
- = === ===
138
131
const result = [
139
- imports ,
132
+ ! this . _module . extracted ? imports : false ,
140
133
exports ,
141
- css
142
- ]
143
- . filter ( Boolean )
144
- . join ( '\n' ) ;
145
-
146
- > >>> >>> feat ( plugins / import ) : add `@import` filter support ( `options.import` ) ( #656 )
147
- cb ( null , result , map ? map . toJSON ( ) : null ) ;
134
+ ! this . _module . extracted ? css : false
135
+ ] . filter ( Boolean ) . join ( '\n' ) ;
136
+
137
+ cb (
138
+ null ,
139
+ result . length >= 1 ? result : '/* CSS Extracted */' ,
140
+ map ? map . toJSON ( ) : null
141
+ ) ;
148
142
149
143
return null ;
150
144
} )
0 commit comments