Used for vite Lazy import js and style.
npm install vite-plugin-lazy-import -D
// 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/*'
}
]
})
]
// ...
})
// 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'
//...
// 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,
VxeModal,
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 { VxeModal } from 'vxe-pc-ui/es/vxe-modal/index.js'
import 'vxe-pc-ui/es/vxe-modal/style.css'
import { Button as VxeButton } from 'vxe-pc-ui/es/button/index.js'
import 'vxe-pc-ui/es/button/style.css'
//...
Thank you to everyone who contributed to this project.
MIT © 2019-present, Xu Liangzhan