I am trying to use WebPack to create a browser package from my isomorphic JS code using commonJS modules. To open the version in package.json, I do the following in my index.js:
var pjson = require("../package.json");
module.exports = {
version: pjson.version
};
However, WebPack will treat the file package.jsonas JavaScript by default, which causes a parser error, since it is actually JSON:
package.json Line 2: Unexpected token :
I read that a plugin is needed for JSON files json-loader, and the module path must be adjusted before json!../package.json. Although this does work for WebPack, it will break the code when run in node.js initially.
So, what is the correct way to link to package.json(or any other JSON file) so that WebPack can create a browser package AND not mess up the code in any way just for WebPack?