Skip to content

AntoineGuglielmi/nuxt-indexes-ts

Repository files navigation

nuxt-indexes-ts

This module allows you to turn

import { Foo } from './whatever/Foo';
import { Bar } from './whatever/Bar';

into

import { Foo, Bar } from './whatever'; // With autocompletion

by creating index.ts files in the directories of your choice.

Installation

npm i nuxt-indexes-ts

Usage

In nuxt.config.ts file:

export default defineNuxtConfig({
  modules: [
    // ...
    'nuxt-indexes-ts'
    // ...
  ],
  indexes: {
    from: ...,
    ignoreAll: ...
  }
})

indexesOptions

The from option

The from option key can be a single string, an array of strings or an array of objects:

// Will watch ONLY inside ./foo directory
from: './foo'

// OR

// Will watch inside ./foo and ./bar directories
from: ['./foo', './bar']

// OR

from: [
  {
    dirs: ...,
    ignore?: ...
  }
]

The dirs and ignore keys (ignore is optional) in object can be a single string or an array of strings.
dirs is pointing to each directory you want to target.
ignore gives all files that will be ignored in these directories.

from: [
  // Will watch inside ./foo directory
  {
    dirs: './foo'
  },
  // Will watch inside ./foo and ./bar directories
  {
    dirs: ['./foo', './bar']
  },
  // Will watch inside ./foo directory, ignoring baz.ts file only in ./foo directory
  {
    dirs: ['./foo'],
    ignore: 'baz.ts'
  },
  // Will watch inside ./foo and ./bar directories, ignoring ipsum.ts file
  // and all files matching the regexp (.*).old.ts in both ./foo and ./bar directories
  {
    dirs: ['./foo', './bar'],
    ignore: ['ipsum.ts', '(.*).old.ts']
  },
]

The ignoreAll option

The ignoreAll option key gives all files that will be ignored for all directories indicated in from option key. By default, all index.ts files are ignored.
It can be a single string or an array of string:

// Will exclude all dolor.ts file
ignoreAll: 'dolor.ts'

// OR

// Will exclude all sit.ts and all amet.ts files
ignoreAll: ['sit.ts', 'amet.ts']

// By default
ignoreAll: ['index.ts']

About

Nuxt module

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published