Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rollup-plugin-json

rollup250.8kMITdeprecated4.0.0TypeScript support: definitely-typed

This module has been deprecated and is no longer maintained. Please use @rollup/plugin-json.

Convert .json files to ES6 modules:

readme

rollup-plugin-json

Convert .json files to ES6 modules:

// import a single property from a JSON file,
// discarding the rest
import { version } from './package.json';
console.log( `running version ${version}` );

// import the whole file as an object
import pkg from './package.json';
console.log( `running version ${pkg.version}` );

Installation

npm install --save-dev rollup-plugin-json

Usage

// rollup.config.js
import json from 'rollup-plugin-json';

export default {
  input: 'src/main.js',
  output: {
    file: 'dist/bundle.js',
    format: 'iife'
  },

  plugins: [
    json({
      // All JSON files will be parsed by default,
      // but you can also specifically include/exclude files
      include: 'node_modules/**',
      exclude: [ 'node_modules/foo/**', 'node_modules/bar/**' ],

      // for tree-shaking, properties will be declared as
      // variables, using either `var` or `const`
      preferConst: true, // Default: false

      // specify indentation for the generated default export —
      // defaults to '\t'
      indent: '  ',

      // ignores indent and generates the smallest code
      compact: true, // Default: false

      // generate a named export for every property of the JSON object
      namedExports: true // Default: true
    })
  ]
};

License

MIT

changelog

rollup-plugin-json changelog

4.0.0

2019-03-18

  • Pass all JSON data through dataToEsm to consistently support "compact" formatting, support empty keys, abandon Node 4 support, add prettier, update dependencies (#53)

3.1.0

2018-09-13

  • Expose "compact" and "namedExports" options (#45)
  • Update rollup-pluginutils to support null values in JSON (#44)
  • Update dependencies and ensure rollup@1.0 compatibility (#46)

3.0.0

2018-05-11

  • No longer create a fake AST to support tree-shaking with upcoming versions of rollup (#41)

2.3.1

2018-05-11

  • Update example in readme (#38)
  • Warn when using this version with upcoming rollup versions

2.3.0

2017-06-03

  • Always parse JSON, so malformed JSON is identified at bundle time (#27)

2.2.0

2017-06-03

  • Add indent option (#24)

2.1.1

2017-04-09

  • Add license to package.json (#25)

2.1.0

2016-12-15

  • Add support for preferConst option (#16)
  • Handle JSON files with no valid identifier keys (#19)

2.0.2

2016-09-07

  • Generate correct fake AST

2.0.1

2016-06-23

  • Return a name

2.0.0

2015-11-05

  • Generate fake AST to avoid unnecessary traversals within Rollup

1.1.0

unpublished

  • Generate named exports alongside default exports

1.0.0

2015-10-25

  • First release