webpack-contrib / json-loader

json loader module for webpack - UNMAINTAINED

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enable use of comments in json file (use json.minify)

emahuni opened this issue · comments

I think it would be convinient to use json.minify to enable and then remove the comments before parsing in json files.

I know comments are not allowed in json, but they are convinient for letting others/your future you, know whats going on without digging in source too much... especially in config files.

Suppose you are using JSON to keep configuration files, which you would like to annotate. Go ahead and insert all the comments you like. Then pipe it through JSMin before handing it to your JSON parser. - Douglas Crockford, 2012

index.js

/*
    MIT License http://www.opensource.org/licenses/mit-license.php
    Author Tobias Koppers @sokra
*/
module.exports = function(source) {
    JSON.minify = require("node-json-minify");

    this.cacheable && this.cacheable();
    var value = typeof source === "string" ? JSON.parse(JSON.minify(source)) : source;
    this.value = [value];
    return "module.exports = " + JSON.stringify(value, undefined, "\t") + ";";
}

package.json

...

  "devDependencies": {
    "node-json-minify": "^1.0.0"
  },

...

That works like a charm... I love this package, well-done man

Added PR Add json minify #29

See #29, please use the json5-loader instead thx 😛