🌜
ğŸŒž
@rollup/plugin-json

@rollup/plugin-json

v4.1.0

Convert .json files to ES6 modules

npm install @rollup/plugin-json

README

npm size libera manifesto

@rollup/plugin-json

🍣 A Rollup plugin which Converts .json files to ES6 modules.

Requirements

This plugin requires an LTS Node version (v8.0.0+) and Rollup v1.20.0+.

Install

Using npm:

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

Usage

Create a rollup.config.js configuration file and import the plugin:

import json from '@rollup/plugin-json';

export default {
  input: 'src/index.js',
  output: {
    dir: 'output',
    format: 'cjs'
  },
  plugins: [json()]
};

Then call rollup either via the CLI or the API.

With an accompanying file src/index.js, the local package.json file would now be importable as seen below:

// src/index.js
import pkg from './package.json';
console.log(`running version ${pkg.version}`);

Options

compact

Type: Boolean
Default: false

If true, instructs the plugin to ignore indent and generates the smallest code.

exclude

Type: String | Array[...String]
Default: null

A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. By default no files are ignored.

include

Type: String | Array[...String]
Default: null

A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.

indent

Type: String
Default: '\t'

Specifies the indentation for the generated default export.

namedExports

Type: Boolean
Default: true

If true, instructs the plugin to generate a named export for every property of the JSON object.

preferConst

Type: Boolean
Default: false

If true, instructs the plugin to declare properties as variables, using either var or const. This pertains to tree-shaking.

Meta

CONTRIBUTING

LICENSE (MIT)

General

License
MIT
Typescript Types
Built-in
Tree-shakeable
Yes

Popularity

GitHub Stargazers
2,784
Community Interest
2,419
Number of Forks
446

Maintenance

Commits
10/219/22050
Last Commit
Open Issues
25
Closed Issues
710
Open Pull Requests
17
Closed Pull Requests
115

Versions

Versions Released
10/219/2201
Latest Version Released
Jun 5, 2020
Current Tags
latest4.1.0

Contributors

shellscape
shellscape
Commits: 350
lukastaegert
lukastaegert
Commits: 40
NotWoods
NotWoods
Commits: 39
benmccann
benmccann
Commits: 19
danielgindi
danielgindi
Commits: 14
tjenkinson
tjenkinson
Commits: 14
LarsDenBakker
LarsDenBakker
Commits: 13
Andarist
Andarist
Commits: 8
guybedford
guybedford
Commits: 7
TrySound
TrySound
Commits: 7
chengcyber
chengcyber
Commits: 4
eight04
eight04
Commits: 3
Acionyx
Acionyx
Commits: 3
Kocal
Kocal
Commits: 3
pnevares
pnevares
Commits: 3