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.
In rc.1 and will likely release 1.0 soon.
yarn add vite-plugin-globby-import
or npm i vite-plugin-globby-import
// 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
.
MIT