Socket
Socket
Sign inDemoInstall

rollup-plugin-local-import

Package Overview
Dependencies
5
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rollup-plugin-local-import

Rollup plugin to manipulate local import/export statements


Version published
Maintainers
1
Install size
22.7 MB
Created

Changelog

Source

1.2.0 (2022-12-01)

Features

  • error-handling: handle errors thrown by callback argument (9ca1390)

Readme

Source

rollup-plugin-local-import

Version

Installation | Configuration | Examples


Rollup plugin for manipulating local import/export statements

Installation

rollup-plugin-local-import should be included in development dependencies.

yarn add --dev rollup-plugin-local-import

Supported Operating Systems

This plugin is built as native addon and supports following operating systems.

node14node16node18
Windows x64
Windows x32
macOS x64
macOS arm64
Linux x64 gnu
Linux x64 musl

Support can be extended to cover more systems if needed.

Configuration

Add plugin in your rollup configuration:

import { defineConfig } from "rollup";
import { localImport } from "rollup-plugin-local-import";

export default defineConfig({
  // ...
  plugins: [localImport((path) => `${path}.js`)],
});

Options

function localImport(callback: Callback): RollupPlugin;
  • callback, (path: string) => string, required

Callback called with each identified local import. Must return string.

function transformLocalImports(path: string): string {
  console.log(`Path is "${path}"`);
  console.log(`Returning "${path}.js"`);

  return `${path}.js`;
}

export default defineConfig({
  // ...
  plugins: [localImport(transformLocalImports)],
});
> Path is "./Header"
> Returning "./Header.js"
- export { default } from './Header';
+ export { default } from './Header.js';

Examples

With localImport(path => path + '.js'):

Input:

export * from "./local-file";
export * from "../file-from-parent-directory";
export * from "some-dependency";

export { a } from "./local-file";
export { b } from "../file-from-parent-directory";
export { c } from "some-dependency";

Output:

export * from "./local-file.js";
export * from "../file-from-parent-directory.js";
export * from "some-dependency"; // Not changed

export { a } from "./local-file.js";
export { b } from "../file-from-parent-directory.js";
export { c } from "some-dependency"; // Not changed

FAQs

Last updated on 01 Dec 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc