Skip to content

luxueyan/vite-plugin-globbyImport

Repository files navigation

vite-plugin-globby-import ⚡

npm node

This plugin is an simple resolution for enchancement of 'Import Expression'. It just replace the globby 'Import Expression' with multiple import lines before the default transforms.

Status

In rc.1 and will likely release 1.0 soon.

Getting Started

Install (yarn or npm)

yarn add vite-plugin-globby-import or npm i vite-plugin-globby-import

Usage

// vite.config.js
module.exports = {
  alias: {
    '/@/': path.resolve(__dirname, 'src'),
  },
  configureServer: [require('vite-plugin-globby-import')],
}

Example import expressions:

import routes from '../pages/**/route.ts'
import imgs from '/@/assets/image/**/*.@(jpg|png)'
// These will be replaced to:
/* 
 * import routes0 from '/@/pages/route.ts'
 * import routes1 from '/@/pages/demo/route.ts'
 * ...
 * const routes = { routes0, routes1, ... }
 * import imgs0 from '/@/assets/image/demo.jpg'
 * import imgs1 from '/@/assets/image/demo/demo.png'
 * ...
 * const imgs = { imgs0, imgs1, ... }
 */

Note: Only work in files includes .vue,.js,.jsx,.ts,.tsx.

License

MIT

About

A simple globbyImport plugin of vite.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published