Skip to content

Commit 6022083

Browse files
feat(index): pass result.root, result.messages as metadata to loaders
1 parent b9c1add commit 6022083

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/index.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const SyntaxError = require('./Error')
3939
*
4040
* @return {cb} cb Result
4141
*/
42-
module.exports = function loader (css, map) {
42+
module.exports = function loader (css, map, meta) {
4343
const options = loaderUtils.getOptions(this) || {}
4444

4545
validateOptions(require('./options.json'), options, 'PostCSS Loader')
@@ -51,7 +51,7 @@ module.exports = function loader (css, map) {
5151

5252
Promise.resolve().then(() => {
5353
const length = Object.keys(options)
54-
.filter((option) => {
54+
.filter((option) => {
5555
switch (option) {
5656
// case 'exec':
5757
case 'ident':
@@ -160,6 +160,11 @@ module.exports = function loader (css, map) {
160160
map.sources = map.sources.map((src) => path.resolve(src))
161161
}
162162

163+
if (!meta) meta = {}
164+
165+
meta.ast = { 'type': 'postcss', root: result.root }
166+
meta.messages = result.messages
167+
163168
if (this.loaderIndex === 0) {
164169
/**
165170
* @memberof loader
@@ -173,6 +178,7 @@ module.exports = function loader (css, map) {
173178

174179
return null
175180
}
181+
176182
/**
177183
* @memberof loader
178184
* @callback cb
@@ -181,7 +187,7 @@ module.exports = function loader (css, map) {
181187
* @param {String} css Result (Raw Module)
182188
* @param {Object} map Source Map
183189
*/
184-
cb(null, css, map)
190+
cb(null, css, map, meta)
185191

186192
return null
187193
})

0 commit comments

Comments
 (0)