New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

rollup-plugin-import-assertions

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-import-assertions

Bundles TC39 import assertions

latest
Source
npmnpm
Version
0.5.0
Version published
Weekly downloads
42
-19.23%
Maintainers
1
Weekly downloads
 
Created
Source

libera manifesto

rollup-plugin-import-assertions

🍣 A Rollup plugin which bundles import assertions.

Two types of assertions are supported: json and css.

Currently, dynamic imports are not supported (PR welcomed).

Install

Using npm:

npm install rollup-plugin-import-assertions --save-dev

Usage

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

import importAssertions from 'rollup-plugin-import-assertions';

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

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' assert { type: 'json' };
console.log(`running version ${pkg.version}`);

It is also possible to import css stylesheets, typically when designing web components:

// src/mycomponent.js
import style from './style.css' assert { type: 'css' };

class MyElement extends HTMLElement {
  constructor() {
    super();
    const root = this.attachShadow({ mode: 'open' });
    root.adoptedStyleSheets = [styles];
    root.innerHTML = `<div>My custom element</div>`;
  }
}

customElements.define('my-element', MyElement);

Options

For the json type of assertions, this plugin accepts the same options as those of @rollup/plugin-json. This makes it straight-forward to move to import assertions, should one wish so.

For the css type of assertions, this plugin accepts the usual include and exclude options.

compact (type: 'json')

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: 'json')

Type: String
Default: '\t'

Specifies the indentation for the generated default export.

namedExports (type: 'json')

Type: Boolean
Default: true

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

preferConst (type: 'json')

Type: Boolean
Default: false

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

Credits

Credits to:

License

license

Keywords

rollup

FAQs

Package last updated on 13 May 2023

Did you know?

Socket

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.

Install

Related posts