Skip to content

Instantly share code, notes, and snippets.

@scottaddie
Last active June 29, 2017 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save scottaddie/0dec634716dffe5f8a4f to your computer and use it in GitHub Desktop.
Save scottaddie/0dec634716dffe5f8a4f to your computer and use it in GitHub Desktop.
C# helper method to parse webpack.assets.json
public static JObject GetWebpackAssetsJson(string applicationBasePath)
{
JObject webpackAssetsJson = null;
string packageJsonFilePath = $"{applicationBasePath}\\{"package.json"}";
using (StreamReader packageJsonFile = File.OpenText(packageJsonFilePath))
{
using (JsonTextReader packageJsonReader = new JsonTextReader(packageJsonFile))
{
JObject packageJson = (JObject)JToken.ReadFrom(packageJsonReader);
JObject webpackConfigJson = (JObject)packageJson["customConfig"]["webpackConfig"];
string webpackAssetsFileName = webpackConfigJson["assetsFileName"].Value<string>();
string webpackBuildDirectory = webpackConfigJson["buildDirectory"].Value<string>();
string webpackAssetsFilePath = $"{applicationBasePath}\\{webpackBuildDirectory}\\{webpackAssetsFileName}";
using (StreamReader webpackAssetsFile = File.OpenText(webpackAssetsFilePath))
{
using (JsonTextReader webpackAssetsReader = new JsonTextReader(webpackAssetsFile))
{
webpackAssetsJson = (JObject)JToken.ReadFrom(webpackAssetsReader);
}
}
}
}
return webpackAssetsJson;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment