Fix #43. Add string options to output json object string.#45
Fix #43. Add string options to output json object string.#45michael-ciniawsky merged 3 commits intowebpack-contrib:masterfrom HairyRabbit:master
string options to output json object string.#45Conversation
| return "module.exports = " + JSON.stringify(value) + ";"; | ||
| this.cacheable && this.cacheable(); | ||
| var value = typeof source === "string" ? JSON.parse(source) : source; | ||
| this.value = [value]; |
There was a problem hiding this comment.
Unrelated, but this can be removed since it was needed in webpack =< v0.8.0 only
There was a problem hiding this comment.
Yeah. this.cacheable isn't needed either.
|
|
||
| ### Options | ||
|
|
||
| #### `string` |
There was a problem hiding this comment.
string => stringify for naming consistency with JSON.stringify
| this.value = [value]; | ||
| var query = loaderUtils.getOptions(this) || {} | ||
| if(query.string) | ||
| return "module.exports = `" + JSON.stringify(value) + "`;"; |
There was a problem hiding this comment.
Please put it on the same line as the if statement or add the {} 😛
There was a problem hiding this comment.
Sidenote - webpack-defaults will catch these.
|
|
||
| #### `string` | ||
|
|
||
| By default, the json-loader will output the json object, set this query parameter to 'ture' can output the json object as a string, e.g. `require('json-loader?string!../index.json')`. It's useful work with `ExtractTextPlugin` |
| return "module.exports = " + JSON.stringify(value) + ";"; | ||
| this.cacheable && this.cacheable(); | ||
| var value = typeof source === "string" ? JSON.parse(source) : source; | ||
| this.value = [value]; |
There was a problem hiding this comment.
Yeah. this.cacheable isn't needed either.
| this.value = [value]; | ||
| var query = loaderUtils.getOptions(this) || {} | ||
| if(query.string) | ||
| return "module.exports = `" + JSON.stringify(value) + "`;"; |
There was a problem hiding this comment.
Sidenote - webpack-defaults will catch these.
| var query = loaderUtils.getOptions(this) || {} | ||
| if(query.string) | ||
| return "module.exports = `" + JSON.stringify(value) + "`;"; | ||
| return "module.exports = " + JSON.stringify(value) + ";"; |
There was a problem hiding this comment.
Do we want to go webpack 2 here? Separate PR would be probably better for that change, though.
| this.value = [value]; | ||
| return "module.exports = " + JSON.stringify(value) + ";"; | ||
| var value = typeof source === "string" ? JSON.parse(source) : source; | ||
| this.value = [value]; |
There was a problem hiding this comment.
this.value = [value] can be removed like this.cacheable, not needed anymore 😛
| var value = typeof source === "string" ? JSON.parse(source) : source; | ||
| this.value = [value]; | ||
| var query = loaderUtils.getOptions(this) || {}; | ||
| var outprefix = this.version && this.version >= 2 ? "export default " : "module.exports = "; |
There was a problem hiding this comment.
query => options
const options = loaderUtils.getOptions(this) || {}
const value = typeof source === "string" ? JSON.parse(source) : source
value = options.stringify ? `${JSON.stringify(value)}` : JSON.stringify(value)
const module = this.version >= 2 ? `export default ${value}` : `module.exports = ${value}`
return module|
@yuffiy Thx && sry for the nitpicking 😛 |
output json object as string.