Automatically import images into the vue project
add them to the types property in your tsconfig.json:
{
"compilerOptions": {
// ...
"types": ["unplugin-vue-auto-img/client"]
}
}
npm i unplugin-vue-auto-img
Vite
// vite.config.ts
import Images from 'unplugin-vue-auto-img/vite'
export default defineConfig({
plugins: [
Images({ /* options */ }),
],
})
Example: playground/
Rollup
// rollup.config.js
import Images from 'unplugin-vue-auto-img/rollup'
export default {
plugins: [
Images({ /* options */ }),
],
}
Webpack
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-vue-auto-img/webpack')({ /* options */ })
]
}
Nuxt
// nuxt.config.js
export default defineNuxtConfig({
modules: [
['unplugin-vue-auto-img/nuxt', { /* options */ }],
],
})
This module works for both Nuxt 2 and Nuxt Vite
Vue CLI
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-vue-auto-img/webpack')({ /* options */ }),
],
},
}
esbuild
// esbuild.config.js
import { build } from 'esbuild'
import Images from 'unplugin-vue-auto-img/esbuild'
build({
plugins: [Images()],
})
unplugin-vue-auto-img
auto import your image from assets/images
by default to your Vue component.
You can only use image variables using camelCase.
--- assets
--- images
--- logo.png
--- App.vue
--- src/App.vue ---
<template>
<div>
<img :src="ILogo">
</div>
</template>