Skip to content

Commit ae9965d

Browse files
madzhupgregberge
authored andcommitted
fix(webpack): use source when possible (#139)
Actually file is read in all cases, this is useless and inefficient.
1 parent 2af4c08 commit ae9965d

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

packages/webpack/src/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,17 @@ function svgrLoader(source) {
4141
)
4242
})
4343

44-
readSvg()
45-
.then(svg => convert(svg, options, { webpack: { previousExport } }))
46-
.then(jsCode => (babel ? pBabelTransform(jsCode) : jsCode))
47-
.then(result => callback(null, result))
48-
.catch(err => callback(err))
44+
const tranformSvg = svg =>
45+
convert(svg, options, { webpack: { previousExport } })
46+
.then(jsCode => (babel ? pBabelTransform(jsCode) : jsCode))
47+
.then(result => callback(null, result))
48+
.catch(err => callback(err))
49+
50+
if (exportMatches) {
51+
readSvg().then(tranformSvg)
52+
} else {
53+
tranformSvg(source)
54+
}
4955
}
5056

5157
export default svgrLoader

0 commit comments

Comments
 (0)