vite-plugin-lazy-import
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

vite-plugin-lazy-import

Used for vite Lazy import js and style.

Installation

npm install vite-plugin-lazy-import -D

Usage

// vite.config.js
import { lazyImport } from 'vite-plugin-lazy-import'

export default defineConfig({
  // ...
  plugins: [
    lazyImport({
      resolvers: [
        {
          lib: 'vxe-pc-ui',
          importStyle: 'css', // import style '*.css'
          esm: true // import directory '/es/*' | '/lib/*'
        }
      ]
    })
  ]
  // ...
})

Lazy import js

// vite.config.js
import { lazyImport } from 'vite-plugin-lazy-import'

lazyImport({
  resolvers: [
    {
      lib: 'vxe-pc-ui',
      resolve ({ name, dirName }) {
        return {
          from: `vxe-pc-ui/es/${dirName}/index.js`
        }
      }
    }
  ]
})
// main.js
// ...
import { VxeUI, VxeButton } from 'vxe-pc-ui'
//...

into this

// ...
import { VxeUI } from 'vxe-pc-ui/es/vxe-ui/index.js'
import { VxeButton } from 'vxe-pc-ui/es/vxe-button/index.js'
//...

Lazy import js and css

// vite.config.js
import { lazyImport } from 'vite-plugin-lazy-import'

lazyImport({
  resolvers: [
    {
      lib: 'vxe-pc-ui',
      importStyle: true,
      resolve ({ name, dirName }) {
        return {
          from: {
            jsPath: `vxe-pc-ui/es/${dirName}/index.js`,
            stylePath: `vxe-pc-ui/es/${dirName}/style.css`
          }
        }
      }
    }
  ]
})
// main.js
// ...
import {
  VxeUI,
  VxeButton,
  Button as VxeButton
} from 'vxe-pc-ui'
//...

into this

// ...
import { VxeUI } from 'vxe-pc-ui/es/vxe-ui/index.js'
import 'vxe-pc-ui/es/vxe-ui/style.css'
import { Button as VxeButton } from 'vxe-pc-ui/es/vxe-button/index.js'
import 'vxe-pc-ui/es/vxe-button/style.css'
//...

License

MIT © 2019-present, Xu Liangzhan

Readme

Keywords

Package Sidebar

Install

npm i vite-plugin-lazy-import

Weekly Downloads

612

Version

1.0.7

License

MIT

Unpacked Size

27.8 kB

Total Files

12

Last publish

Collaborators

  • x-extends