Skip to content

Commit

Permalink
fix(webpack): use source when possible (#139)
Browse files Browse the repository at this point in the history
Actually file is read in all cases, this is useless and inefficient.
  • Loading branch information
madzhup authored and gregberge committed Aug 13, 2018
1 parent 2af4c08 commit ae9965d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/webpack/src/index.js
Expand Up @@ -41,11 +41,17 @@ function svgrLoader(source) {
)
})

readSvg()
.then(svg => convert(svg, options, { webpack: { previousExport } }))
.then(jsCode => (babel ? pBabelTransform(jsCode) : jsCode))
.then(result => callback(null, result))
.catch(err => callback(err))
const tranformSvg = svg =>
convert(svg, options, { webpack: { previousExport } })
.then(jsCode => (babel ? pBabelTransform(jsCode) : jsCode))
.then(result => callback(null, result))
.catch(err => callback(err))

if (exportMatches) {
readSvg().then(tranformSvg)
} else {
tranformSvg(source)
}
}

export default svgrLoader

0 comments on commit ae9965d

Please sign in to comment.