Skip to content

dappface/jsonify-webpack-plugin

Repository files navigation

Build Status Lint Status codecov

Jsonify Webpack Plugin

Plugin that creates JSON file with file name and stringified code

Install

  npm i -D jsonify-webpack-plugin

Usage

webpack.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) {..."
}

Motivation

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.

About

Creates JSON file with file name and stringified code

Resources

Stars

Watchers

Forks

Packages

No packages published