@hqjs/babel-plugin-transform-json-imports

0.0.6 • Public • Published

https://hqjs.org

Transform json imports

Installation

npm install hqjs@babel-plugin-transform-json-imports

Usage

{
  "plugins": [["hqjs@babel-plugin-transform-json-imports", { "dirname": "/json/directory", "root": "/root/directory" }]]
}

If you are invoking this plugin from javascript it becomes possible to pass filesystem implementation trough fs option, it expects the object with readFileSync method defined.

Transformation

Transforms .json imports into inplace definition e.g. having file values.json

{
  "a": 1,
  "b": 2,
  "c": 3
}

and importing it

import values from './values.json';
// Or with destructure
import {a, b} from './values.json';

or similar expressions with require

const values = require('./values.json');
// Or with destructure
const {a, b} = require('./values.json');

we will obtain

const values = {a: 1, b: 2, c: 3};
const {a, b} = {a: 1, b: 2};

Package Sidebar

Install

npm i @hqjs/babel-plugin-transform-json-imports

Homepage

hqjs.org

Weekly Downloads

4

Version

0.0.6

License

MIT

Unpacked Size

14.2 kB

Total Files

6

Last publish

Collaborators

  • hqjs