mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
ec2c8c6784
* Fix .json import error This is a regression we've added by #926 (tree-shaking-support) * Add a test case.
25 lines
735 B
JavaScript
25 lines
735 B
JavaScript
import loaderUtils from 'loader-utils'
|
|
|
|
module.exports = function (content, sourceMap) {
|
|
this.cacheable()
|
|
|
|
const query = loaderUtils.parseQuery(this.query)
|
|
const name = query.name || '[hash].[ext]'
|
|
const context = query.context || this.options.context
|
|
const regExp = query.regExp
|
|
const opts = { context, content, regExp }
|
|
const interpolatedName = loaderUtils.interpolateName(this, name, opts)
|
|
|
|
const emit = (code, map) => {
|
|
this.emitFile(interpolatedName, code, map)
|
|
this.callback(null, code, map)
|
|
}
|
|
|
|
if (query.transform) {
|
|
const transformed = query.transform({ content, sourceMap, interpolatedName })
|
|
return emit(transformed.content, transformed.sourceMap)
|
|
}
|
|
|
|
return emit(content, sourceMap)
|
|
}
|