Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
rollup-plugin-json
Advanced tools
The rollup-plugin-json package is a Rollup plugin that allows you to import JSON files into your JavaScript bundles. It converts JSON files into ES6 modules, enabling you to use JSON data directly in your Rollup projects.
Import JSON files
This feature allows you to import JSON files directly into your JavaScript code. The JSON data is converted into an ES6 module, making it easy to work with JSON data in your Rollup projects.
import data from './data.json';
console.log(data);
Convert JSON to ES6 modules
The plugin converts JSON files into ES6 modules, allowing you to access JSON properties as if they were part of a JavaScript object. This makes it convenient to manage configuration or data files in JSON format.
import config from './config.json';
console.log(config.setting);
rollup-plugin-commonjs is a Rollup plugin that allows you to convert CommonJS modules to ES6, so they can be included in a Rollup bundle. While it primarily focuses on CommonJS modules, it can also handle JSON imports, similar to rollup-plugin-json, but with broader functionality for module conversion.
rollup-plugin-node-resolve is a Rollup plugin that helps in resolving Node.js modules, including JSON files. It allows you to import JSON files as modules, similar to rollup-plugin-json, but it also provides additional features for resolving other types of modules and dependencies.
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}` );
npm install --save-dev rollup-plugin-json
// 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
})
]
};
MIT
FAQs
Convert .json files to ES6 modules:
The npm package rollup-plugin-json receives a total of 161,137 weekly downloads. As such, rollup-plugin-json popularity was classified as popular.
We found that rollup-plugin-json demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.