Giter VIP home page Giter VIP logo

vite-plugin-barrels's Introduction

vite-plugin-barrels

Automatically generate barrels for your folders! This plugin taps into the Vite plugin system to automatically recreate barrels on build and whenever a file gets updated or created.

⚠️ Warning
This will remove all content existing in the index of the entry directory and all subdirectories. Only point the entry at a folder with no index files!

Installation

npm install -D vite-plugin-barrels

Usage

Add the following to your Vite configuration:

// vite.config.js
import barrels from 'vite-plugin-barrels';

export default {
    // ...
    plugins: [
        barrels({
            entry: '<your entry folder>',
            extension: '<whatever extension>'
        })
    ]
}

Example

This is an example for Svelte. The extension to barrel is .svelte with the entry being src/lib.

// vite.config.js
import barrels from 'vite-plugin-barrels';

export default {
    // ...
    plugins: [
        barrels({
            entry: 'src/lib',
            extension: '.svelte'
        })
    ]
}

Before the build, the directory structure looks like this:

src
└───lib
    │   Another.svelte
    │   Component.svelte
    │
    └───layout
            Container.svelte

After the build, the barrels get generated:

src
└───lib
    │   Another.svelte
    │   Component.svelte
    │   index.ts
    │
    └───layout
            Container.svelte
            index.ts

Barrel content:

// src/lib/index.ts
// Generated by vite-plugin-barrels

export * from "./layout";
export { default as Another } from "./Another.svelte";
export { default as Test } from "./Test.svelte";
// src/lib/layout/index.ts
// Generated by vite-plugin-barrels

export { default as Container } from "./Container.svelte";

Configuration

interface Options {
    /**
     * Starting directory
     */
    entry: string;

    /**
     * File extension to search for
     */
    extension: string | string[] | RegExp;

    /**
     * Weather or not to use typescript
     * @default true When tsconfig.json is found
     */
    ts?: boolean;
}

vite-plugin-barrels's People

Contributors

bluefrog130 avatar shoveller avatar

Stargazers

 avatar Peter Adam avatar

Watchers

James Cloos avatar  avatar

Forkers

shoveller

vite-plugin-barrels's Issues

Pattern matching for paths and extensions

Hi, very nice and useful plugin 👍

It would be great if entry and extension would support patterns like lib/components/* or lib/components/** to be able to specify if I wand barrel file for only one level of directories or for all nested folders.

Also for me, it's a dealbreaker for me that I can't exclude some files/folders. For example I need to exclude all story-book stories. With pattern matching, it would be possible (*.tsx will not match foo.stories.tsx).

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.