Code Monkey home page Code Monkey logo

rollup-plugin-local-import's Introduction

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

rollup-plugin-local-import's People

Contributors

ariperkkio avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rollup-plugin-local-import's Issues

re-exporting named imports: `thread '<unnamed>' panicked`

Re-exporting a named import causes plugin to panic.

import { sideEffects } from "./some-file";

sideEffects();

export { sideEffects };
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', src/parser.rs:31:38
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.