Skip to content

Rollup plugin for manipulating local import/export statements | πŸ¦€

Notifications You must be signed in to change notification settings

AriPerkkio/rollup-plugin-local-import

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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.

node14 node16 node18
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

About

Rollup plugin for manipulating local import/export statements | πŸ¦€

Topics

Resources

Stars

Watchers

Forks

Languages