Vue HTML Loader

1.2.4 · abandoned · verified Sun Apr 19

The `vue-html-loader` (version 1.2.4) is a Webpack loader specifically designed to process HTML templates for Vue.js applications. It functions as a fork of the generic `html-loader`, adapted to recognize and handle specific Vue template requirements. Its core functionality involves exporting HTML as a string, enabling asset path resolution for elements like `<img>` tags, and supporting optional HTML minimization. The loader also provides configuration options for custom tag-attribute processing and handling 'root-relative' URLs within HTML. However, its last update was in early 2016, indicating it is no longer actively maintained. Due to the significant evolution of both Webpack (v4/v5) and Vue.js (v2/v3, and modern build tools like Vue CLI and Vite), this loader is largely obsolete and incompatible with contemporary Vue development workflows.

Common errors

Warnings

Install

Imports

Quickstart

This `webpack.config.js` snippet demonstrates how to configure `vue-html-loader` to process HTML files, resolve image assets using `file-loader`, and enable optional HTML minimization. It shows both direct loader usage and older `vue` config block options.

const path = require('path');

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.html$/,
        use: ['vue-html-loader?root=.', 'html-loader'], // Chaining with html-loader might be necessary for some features
        exclude: /index.html/ // Typically exclude main index.html if using HtmlWebpackPlugin
      },
      {
        test: /\.(png|jpe?g|gif|svg)$/i,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: '[name].[hash].[ext]',
              outputPath: 'assets/images',
            },
          },
        ],
      },
      // Note: For actual Vue SFCs, you would use vue-loader and vue-template-compiler
      // This example focuses on standalone HTML templates processed by vue-html-loader
    ]
  },
  // Example of vue-html-loader specific options (older Webpack config style)
  vue: {
    html: {
      minimize: true, // Example: Enable HTML minimization
      // Other options like 'attrs' can be specified here as well for older configs
      // e.g., attrs: ['img:src', 'img:data-src']
    }
  },
  // Ensure Webpack 5 Asset Modules are handled correctly alongside older loaders
  // For Webpack 5, it's generally recommended to use built-in Asset Modules instead of file-loader/url-loader
  // However, for compatibility with vue-html-loader, older loaders might be required.
};

view raw JSON →