A webpack loader for automatic Vuetify component imports and progressive image generation
—
Automatic Vuetify component importing functionality that analyzes Vue single-file components and automatically injects import statements for used Vuetify components.
Webpack plugin that integrates vuetify-loader with vue-loader to automatically process Vue components.
/**
* Webpack plugin for automatic Vuetify component imports
* @param {VuetifyLoaderPluginOptions} options - Configuration options
*/
class VuetifyLoaderPlugin {
constructor(options = {});
/**
* Apply the plugin to webpack compiler
* @param {webpack.Compiler} compiler - Webpack compiler instance
*/
apply(compiler);
}
interface VuetifyLoaderPluginOptions {
/** Array of custom matcher functions for non-Vuetify components */
match?: MatcherFunction[];
}Usage Example:
// webpack.config.js
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin');
module.exports = {
plugins: [
new VuetifyLoaderPlugin({
match: [
// Custom matcher for project components
(originalTag, { kebabTag, camelTag, path, component }) => {
if (kebabTag.startsWith('core-')) {
return [camelTag, `import ${camelTag} from '@/components/core/${camelTag.substring(4)}.vue'`];
}
}
]
})
]
};Main webpack loader function that processes Vue component content and injects import statements.
/**
* Main webpack loader function for automatic component imports
* @param {string} content - Vue component source code
* @param {object} sourceMap - Source map object
* @returns {void} - Calls this.callback with processed content
*/
function vuetifyLoader(content, sourceMap);Process Flow:
Define custom component matching logic for project-specific components.
/**
* Custom matcher function for component identification
* @param {string} originalTag - Original tag name from template
* @param {MatcherContext} context - Additional context data
* @returns {[string, string] | undefined} - [componentName, importStatement] or undefined
*/
type MatcherFunction = (
originalTag: string,
context: MatcherContext
) => [string, string] | undefined;
interface MatcherContext {
/** Tag name in kebab-case format */
kebabTag: string;
/** Tag name in PascalCase format */
camelTag: string;
/** Relative path to current Vue file */
path: string;
/** Parsed Vue component descriptor */
component: ComponentDescriptor;
}Usage Example:
// Custom matcher for UI library components
function customMatcher(originalTag, { kebabTag, camelTag, path, component }) {
if (kebabTag.startsWith('ui-')) {
const componentName = camelTag.replace('Ui', '');
return [componentName, `import { ${componentName} } from '@/ui-library'`];
}
if (kebabTag.startsWith('icon-')) {
return [camelTag, `import ${camelTag} from '@/icons/${camelTag}.vue'`];
}
return undefined;
}Internal matcher that identifies standard Vuetify components.
/**
* Built-in matcher for Vuetify components
* @param {string} _ - Unused original tag parameter
* @param {object} context - Matcher context with kebabTag and camelTag
* @returns {[string, string] | undefined} - Component match result
*/
function vuetifyMatcher(_, { kebabTag, camelTag });Behavior:
String transformation utilities used by the loader for tag processing.
/**
* Convert kebab-case string to camelCase
* @param {string} str - Input string in kebab-case
* @returns {string} - camelCase string
*/
function camelize(str);
/**
* Capitalize first letter of string
* @param {string} str - Input string
* @returns {string} - String with capitalized first letter
*/
function capitalize(str);
/**
* Convert camelCase string to kebab-case
* @param {string} str - Input string in camelCase
* @returns {string} - kebab-case string
*/
function hyphenate(str);The plugin must be added to webpack plugins array and requires vue-loader to be present:
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin');
module.exports = {
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
}
]
},
plugins: [
new VuetifyLoaderPlugin()
]
};Install with Tessl CLI
npx tessl i tessl/npm-vuetify-loader