This repository has been archived by the owner on Aug 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add
stringify
option to output JSON object as string (#45)
- Loading branch information
1 parent
2993ea0
commit dbf1fa5
Showing
3 changed files
with
25 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
/* | ||
MIT License http://www.opensource.org/licenses/mit-license.php | ||
Author Tobias Koppers @sokra | ||
MIT License http://www.opensource.org/licenses/mit-license.php | ||
Author Tobias Koppers @sokra | ||
*/ | ||
var loaderUtils = require('loader-utils'); | ||
|
||
module.exports = function(source) { | ||
this.cacheable && this.cacheable(); | ||
var value = typeof source === "string" ? JSON.parse(source) : source; | ||
this.value = [value]; | ||
return "module.exports = " + JSON.stringify(value) + ";"; | ||
var value = typeof source === "string" ? JSON.parse(source) : source; | ||
var options = loaderUtils.getOptions(this) || {}; | ||
value = JSON.stringify(value) | ||
value = options.stringify ? `'${value}'` : value | ||
var module = this.version && this.version >= 2 ? `export default ${value};` : `module.exports = ${value};`; | ||
return module | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters