Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
revert: add stringify option to output JSON object as string (#43) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra authored and joshwiens committed Jul 22, 2017
1 parent fa6392c commit e528e1d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ import json from 'file.json';
import json from 'json-loader!file.json';
```



### Options

#### `stringify`

By default, the json-loader will output the json object, set this query parameter to 'true' can output the json object as a string, e.g. `require('json-loader?stringify!../index.json')`.




<h2 align="center">Maintainer</h2>

<table>
Expand All @@ -87,7 +76,6 @@ By default, the json-loader will output the json object, set this query paramete
</tbody>
</table>


[npm]: https://img.shields.io/npm/v/json-loader.svg
[npm-url]: https://npmjs.com/package/json-loader

Expand Down
20 changes: 8 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
/*
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) {
var value = typeof source === "string" ? JSON.parse(source) : source;
var options = loaderUtils.getOptions(this) || {};
value = JSON.stringify(value)
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029');
value = options.stringify ? `'${value}'` : value
var module = this.version && this.version >= 2 ? `export default ${value};` : `module.exports = ${value};`;
return module
var value = typeof source === "string" ? JSON.parse(source) : source;
value = JSON.stringify(value)
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029');
var module = this.version && this.version >= 2 ? `export default ${value};` : `module.exports = ${value};`;
return module;
}
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
"repository": {
"type": "git",
"url": "https://github.com/webpack/json-loader.git"
},
"dependencies": {
"loader-utils": "^1.0.3"
}
}

0 comments on commit e528e1d

Please sign in to comment.