2016-11-16 07:04:57 +00:00
|
|
|
import loaderUtils from 'loader-utils'
|
2016-10-15 16:17:27 +00:00
|
|
|
|
2016-12-02 01:43:38 +00:00
|
|
|
module.exports = function (content, sourceMap) {
|
2016-10-15 16:17:27 +00:00
|
|
|
this.cacheable()
|
|
|
|
|
2017-02-22 18:08:49 +00:00
|
|
|
const query = loaderUtils.getOptions(this)
|
2016-10-15 16:17:27 +00:00
|
|
|
const name = query.name || '[hash].[ext]'
|
|
|
|
const context = query.context || this.options.context
|
|
|
|
const regExp = query.regExp
|
|
|
|
const opts = { context, content, regExp }
|
2016-11-16 07:04:57 +00:00
|
|
|
const interpolatedName = loaderUtils.interpolateName(this, name, opts)
|
2016-10-15 16:17:27 +00:00
|
|
|
|
2017-01-31 06:31:27 +00:00
|
|
|
const emit = (code, map) => {
|
|
|
|
this.emitFile(interpolatedName, code, map)
|
|
|
|
this.callback(null, code, map)
|
|
|
|
}
|
2016-10-15 16:17:27 +00:00
|
|
|
|
2017-01-31 06:31:27 +00:00
|
|
|
if (query.transform) {
|
2017-02-01 06:17:15 +00:00
|
|
|
const transformed = query.transform({ content, sourceMap, interpolatedName })
|
2017-01-31 06:31:27 +00:00
|
|
|
return emit(transformed.content, transformed.sourceMap)
|
|
|
|
}
|
|
|
|
|
|
|
|
return emit(content, sourceMap)
|
2016-10-15 16:17:27 +00:00
|
|
|
}
|