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

revert: add stringify option to output JSON object as string (#43) #52

Merged
merged 4 commits into from
May 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,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 Down Expand Up @@ -109,7 +98,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"
}
}