-
Notifications
You must be signed in to change notification settings - Fork 82
Fix #43. Add string
options to output json object string.
#45
Conversation
index.js
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated, but this can be removed since it was needed in webpack =< v0.8.0 only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. this.cacheable
isn't needed either.
README.md
Outdated
|
||
### Options | ||
|
||
#### `string` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string
=> stringify
for naming consistency with JSON.stringify
index.js
Outdated
this.value = [value]; | ||
var query = loaderUtils.getOptions(this) || {} | ||
if(query.string) | ||
return "module.exports = `" + JSON.stringify(value) + "`;"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put it on the same line as the if
statement or add the {}
😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sidenote - webpack-defaults will catch these.
README.md
Outdated
|
||
#### `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` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
over ture
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tune the last sentence too.
index.js
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. this.cacheable
isn't needed either.
index.js
Outdated
this.value = [value]; | ||
var query = loaderUtils.getOptions(this) || {} | ||
if(query.string) | ||
return "module.exports = `" + JSON.stringify(value) + "`;"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sidenote - webpack-defaults will catch these.
index.js
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to go webpack 2 here? Separate PR would be probably better for that change, though.
index.js
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.value = [value]
can be removed like this.cacheable
, not needed anymore 😛
index.js
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
@yuffiy Thx && sry for the nitpicking 😛 |
output json object as string.