Giter VIP home page Giter VIP logo

vite-plugin-auto-include's Introduction

A tool that can auto add babel-plugin-import's result to vite's Pre-bundling dependencies.

Why vite-plugin-auto-include

When we use babel-plugin-import or the same tool to minimize our bandle,the vite(server mode) always reload page because of it find new dependencies. Use this tool,it can auto add to vite's Pre-bundling dependencies.

Install

yarn add vite-plugin-auto-include --dev or npm install vite-plugin-auto-include -D

Usage

//vite.config.ts or vite.config.js
import autoInclude from 'vite-plugin-auto-include';

export default defineConfig({
  ...
  plugins: [
    autoInclude({
      libraryName: 'antd',
      libraryDirectory: 'es',
      style: true
    }),
    ...
  ], 
  ...
})

options

//options can be AutoIncludeOpt or AutoIncludeOpt[]
interface AutoIncludeOpt {
    libraryName: string;
    /** default es */
    libraryDirectory?: string;
    /** default style */
    styleLibraryDirectory?: string;
    /** 
     * - true => index.js;
     * - string => string.js;  for example: if set css , will return css.js;
     * - function => path; notice : can't return .less or .scss or .stylus;
     */
    style?: true | string | ((name: string, path?: string) => string | null | undefined);
    /** ignore some conponet's directory */
    ignoreDirs?: string[];
}

For Example:

  autoInclude({
    libraryName: 'antd',
    libraryDirectory: 'es',
    style: (name) => {
      if (name === '_util' || name === 'locale'|| name==='style') return null;
      return `antd/es/${name}/style`;//real fiel:`antd/es/${name}/style/index.js`
    },
  }),
  //or
  autoInclude([
    {
      libraryName: 'antd',
      libraryDirectory: 'es',
      ignoreDirs: ['_util', 'locale', 'style'],
      style: true
    },
	  {
      libraryName: 'antd-mobile',
      libraryDirectory: 'es',
      style: 'css'
  	}
  ]),

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.