Skip to content

Commit f1a67dd

Browse files
feat(index): flag module for rebuilding ( module.extracted)
1 parent 25bff9b commit f1a67dd

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

src/index.js

+20-26
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import/order,
44
no-shadow,
55
no-param-reassign
66
*/
7+
import path from 'path'
8+
79
import schema from './options.json';
810
import { getOptions } from 'loader-utils';
911
import validateOptions from 'schema-utils';
@@ -28,11 +30,6 @@ export default function loader(css, map, meta) {
2830
// Loader Mode (Async)
2931
const cb = this.async();
3032
const file = this.resourcePath;
31-
<<<<<<< HEAD
32-
33-
=======
34-
35-
>>>>>>> feat(plugins/import): add `@import` filter support (`options.import`) (#656)
3633
// Loader Options
3734
const options = Object.assign({}, DEFAULTS, getOptions(this));
3835

@@ -70,19 +67,20 @@ export default function loader(css, map, meta) {
7067
map = options.sourceMap
7168
? {
7269
prev: map || false,
73-
inline: false,
74-
annotation: false,
70+
inline: this._module.extracted ? false : true,
71+
annotation: this._module.extracted ? false : true,
7572
sourcesContent: true,
7673
}
7774
: false;
7875

7976
return postcss(plugins)
8077
.process(css, {
81-
from: `/css-loader!${file}`,
78+
// `/css-loader!${file}`
79+
from: file,
8280
map,
83-
to: file,
81+
to: this.rootContext
8482
})
85-
.then(({ root, css, map, messages }) => {
83+
.then(({ css, map, messages }) => {
8684
if (meta && meta.messages) {
8785
messages = messages.concat(meta.messages);
8886
}
@@ -120,31 +118,27 @@ export default function loader(css, map, meta) {
120118

121119
return exports;
122120
}, '');
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}\``
127121

128122
imports = imports ? `// CSS Imports\n${imports}\n` : false;
129123
exports = exports ? `// CSS Exports\n${exports}\n` : false;
130124
css = `// CSS\nexport default \`${css}\``;
131125

126+
// Mark module as CSS Module
127+
this._module.css = true
128+
132129
// TODO(michael-ciniawsky)
133130
// triage if and add CSS runtime back
134-
<<<<<<< HEAD
135-
const result = [imports, exports, css].filter(Boolean).join('\n');
136-
137-
=======
138131
const result = [
139-
imports,
132+
!this._module.extracted ? imports : false,
140133
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+
);
148142

149143
return null;
150144
})

0 commit comments

Comments
 (0)