Skip to content

Commit

Permalink
Add support for source maps (#4)
Browse files Browse the repository at this point in the history
Add support for source maps
  • Loading branch information
TehShrike committed Jun 11, 2019
2 parents 5c6d5d8 + dac2453 commit 0fc0019
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@ module.exports = (context = {}) => {
const { useConfigFile = true, configFilePath, plugins = [] } = context

if (useConfigFile === false) {
return ({ content }) => Promise.resolve(process(plugins, content))
return ({ content, fileName }) => Promise.resolve(process(plugins, content, fileName))
} else {
const configPromise = postcssLoadConfig(context, configFilePath)

return ({ content }) => configPromise.then(
({ plugins }) => process(plugins, content)
return ({ content, fileName }) => configPromise.then(
({ plugins }) => process(plugins, content, fileName)
)
}
}

function process(plugins, css) {
return postcss(plugins)
.process(css)
.then(code => ({ code }))
function process(plugins, css, filename) {
return postcss(plugins)
.process(css, {
from: filename,
map: {
inline: false
}
})
.then(result => ({
code: result.css,
map: result.map
}));
}

0 comments on commit 0fc0019

Please sign in to comment.