A webpack loader for automatic Vuetify component imports and progressive image generation
—
Progressive image loading functionality that generates low-resolution placeholders for Vuetify image components, providing smooth loading experiences and perceived performance improvements.
Vue template compiler module that transforms image source attributes to enable progressive loading.
/**
* Vue compiler module for progressive image loading
* Transforms v-img, v-card-media, and v-carousel-item components
*/
const VuetifyProgressiveModule = {
/** Post-transform function for Vue template compilation */
postTransformNode: Function
};
/**
* Transform function for image components
* @param {VNode} node - Vue template node
* @returns {VNode} - Transformed node with progressive loading
*/
function postTransformNode(node);Usage Example:
// webpack.config.js
const { VuetifyProgressiveModule } = require('vuetify-loader');
module.exports = {
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
compilerOptions: {
modules: [VuetifyProgressiveModule]
}
}
}
]
}
};Webpack loader that processes image files and generates low-resolution placeholders.
/**
* Webpack loader for generating progressive image placeholders
* @param {Buffer} contentBuffer - Image file buffer
* @returns {void} - Calls callback with processed result
*/
function progressiveLoader(contentBuffer);
// Loader properties
progressiveLoader.raw = true; // Handles binary dataWebpack Rule Configuration:
module.exports = {
module: {
rules: [
{
test: /\.(png|jpe?g|gif)$/,
resourceQuery: /vuetify-preload/,
use: [
{
loader: 'vuetify-loader/progressive-loader',
options: {
size: 9, // Preview size in pixels
sharp: false, // Use sharp library
graphicsMagick: false // Use GraphicsMagick
}
},
{
loader: 'url-loader',
options: { limit: 8000 }
}
]
}
]
}
};Options for controlling progressive image generation behavior.
interface ProgressiveLoaderOptions {
/**
* Minimum dimensions of preview images in pixels
* @default 9
*/
size?: number;
/**
* Use sharp library instead of GraphicsMagick
* Better for environments without ImageMagick
* @default false
*/
sharp?: boolean;
/**
* Use GraphicsMagick instead of ImageMagick
* @default false
*/
graphicsMagick?: boolean;
}The progressive loader follows this process:
The loader produces modules with both original and placeholder data:
// Generated module structure
interface ProgressiveImageModule {
/** Original image source (URL or data URI) */
src: string;
/** Low-resolution placeholder as data URI */
lazySrc: string;
/** Aspect ratio (width/height) for layout */
aspect: number;
}Example Usage in Templates:
<template>
<!-- Automatic transformation by VuetifyProgressiveModule -->
<v-img src="@/assets/hero-image.jpg"></v-img>
<!-- Manual progressive loading -->
<v-img :src="require('@/assets/product.jpg?vuetify-preload')"></v-img>
<!-- Selective lazy loading -->
<v-img src="@/assets/background.jpg?lazy"></v-img>
</template>Use Rule.oneOf to prevent conflicts with other image loaders:
{
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)(\?.*)?$/,
oneOf: [
{
test: /\.(png|jpe?g|gif)$/,
resourceQuery: /vuetify-preload/,
use: [
'vuetify-loader/progressive-loader',
{
loader: 'url-loader',
options: { limit: 8000 }
}
]
},
{
loader: 'url-loader',
options: { limit: 8000 }
}
]
}For dynamic paths or loops, manual require statements are needed:
<template>
<!-- Dynamic images in loops -->
<v-img
v-for="i in imageCount"
:key="i"
:src="require(`@/images/gallery-${i}.jpg?vuetify-preload`)"
></v-img>
<!-- Conditional progressive loading -->
<v-img
:src="lazy ? require(`@/assets/${image}?vuetify-preload`) : require(`@/assets/${image}`)"
></v-img>
</template>Apply progressive loading only to specific images using query parameters:
// Webpack rule for selective loading
{
test: /\.(png|jpe?g|gif)$/,
resourceQuery: /lazy\?vuetify-preload/,
use: ['vuetify-loader/progressive-loader']
}<template>
<!-- Only images with ?lazy will get progressive loading -->
<v-img src="@/assets/hero.jpg?lazy"></v-img>
<v-img src="@/assets/icon.jpg"></v-img> <!-- No progressive loading -->
</template>// Required dependencies
"gm": "^1.23.1" // GraphicsMagick/ImageMagick bindings
"loader-utils": "^1.1.0" // Webpack loader utilities
// Optional dependencies
"sharp": "^0.x.x" // Alternative image processingThe progressive module automatically transforms these Vuetify components:
v-img: Primary image componentv-card-media: Deprecated card media componentv-carousel-item: Carousel slide imagesError Logging Example:
// Errors are logged to console but don't break the build
gm(path).size(function(err, info) {
if (err) console.error(err);
// Process continues with error handling
});Install with Tessl CLI
npx tessl i tessl/npm-vuetify-loader