vite-plugin-base-src
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Vite Base Src Plugin

A simple Vite plugin which allows absolute import statements for files in src folder

Build status

Installation

Install the plugin

npm install --save vite-plugin-base-src

Usage

  • Apply the plugin in your vite.config.js file
import { defineConfig } from 'vite';
import ViteBaseSrcPlugin from 'vite-plugin-base-src';

export default defineConfig({
  plugins: [
    ViteBaseSrcPlugin({
      src: 'src',
    }),
  ]
});
  • Given that you have a file structure like this
src
|- utils
   |- pusher.ts
|- components
   |- App.ts
  • Normally, inside App.js, you have to use the following statement to import pusher.ts
import pusher from '../utils/pusher';
  • With this plugin, you can simply import like this
import pusher from 'utils/pusher';

Configuration

ViteBaseSrcPlugin({
  src: 'src', // Required. Src folder.
  fileExtensions: ['.js', '.mjs'] // Default: ['.js', '.ts', '.jsx', '.tsx']. A list of accepted file extensions. This list is used when resolving a folder or a file without extension in the import statement.
})

License

This project is licensed under the terms of the MIT License.

/vite-plugin-base-src/

    Package Sidebar

    Install

    npm i vite-plugin-base-src

    Weekly Downloads

    0

    Version

    1.0.4

    License

    MIT

    Unpacked Size

    8.42 kB

    Total Files

    6

    Last publish

    Collaborators

    • uendno