@rollup/plugin-json
Convert .json files to ES6 modules
Last updated 5 years ago by shellscape .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @rollup/plugin-json 
SYNC missed versions from official npm registry.

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 (v14.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 { readFileSync } from 'fs';

const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
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 picomatch 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 picomatch pattern, or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.

includeArbitraryNames

Type: Boolean
Default: false

If true and namedExports is true, generates a named export for not a valid identifier properties of the JSON object by leveraging the "Arbitrary Module Namespace Identifier Names" feature.

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)

Current Tags

  • 6.1.0                                ...           latest (a year ago)

11 Versions

  • 6.1.0                                ...           a year ago
  • 6.0.1                                ...           a year ago
  • 6.0.0                                ...           2 years ago
  • 5.0.2                                ...           2 years ago
  • 5.0.1                                ...           2 years ago
  • 5.0.0                                ...           2 years ago
  • 4.1.0                                ...           4 years ago
  • 4.0.3                                ...           5 years ago
  • 4.0.2                                ...           5 years ago
  • 4.0.1                                ...           5 years ago
  • 4.0.0                                ...           5 years ago
Downloads
Total 8
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (3)

© 2010 - cnpmjs.org x YWFE | Home | YWFE