npm i -D jsonify-webpack-pluginwebpack.config.js
const JsonifyWebpackConfig = require('jsonify-webpack-plugin')
const path = require('path')
module.exports = {
entry: 'index.js',
output: {
path: path.resolve(__dirname + 'dist'),
filename: 'bundle.js'
},
plugins: [new JsonifyWebpackPlugin(['bundle.js'])]
}This will generate a file dist/index.json containing the following
{
"bundle.js": "/******/ (function(modules) {..."
}I had situation once that I need to import bundled JavaScript code in React Native for injecting into WebView. The WebView component takes stringified JS code through injectedJavaScript prop.
Metro bundler doesn't support importing .js file as a raw string so that I needed to convert a bundle.js file into either .json or .txt format.