Vue Component Documentation Webpack Loader

2.0.1 · active · verified Tue Apr 21

vue-docgen-loader is a Webpack loader designed to parse Vue component files, including single-file components (.vue) and standard JavaScript/TypeScript files exporting Vue components. It leverages vue-docgen-api to extract detailed documentation metadata (props, events, methods, slots, etc.) and injects this information directly into the compiled component's module export. This enables various development tools, such as automatically generated style guides (e.g., Vue Styleguidist), component explorers, or dynamic property editors, to access component specifications at runtime. The current stable version is 2.0.1. While there isn't a strict release cadence, updates appear to be made as needed, often for dependency bumps or feature enhancements. Its primary differentiation lies in seamlessly integrating documentation generation into the Webpack build pipeline, making component documentation an intrinsic part of the application bundle.

Common errors

Warnings

Install

Imports

Quickstart

Configures Webpack to use `vue-docgen-loader` for Vue Single File Components, ensuring documentation metadata is injected into component exports at `__docgenInfo` for runtime access. It demonstrates `enforce: 'post'` for correct loader ordering and basic setup with `vue-loader` and `HtmlWebpackPlugin` for a runnable development server.

const path = require('path');
const { VueLoaderPlugin } = require('vue-loader');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  mode: 'development',
  entry: './src/main.js', // Assuming a main entry point for a Vue app
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      {
        // Apply vue-docgen-loader to Vue Single File Components.
        // 'enforce: "post"' ensures it runs after vue-loader, which is
        // crucial for correctly parsing the Vue component's script.
        test: /\.vue$/,
        loader: 'vue-docgen-loader',
        options: {
          // Customize the property name where documentation will be injected.
          // Default is '__docgenInfo'.
          injectAt: '__docgenInfo'
        },
        enforce: 'post'
      }
    ]
  },
  plugins: [
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      template: './public/index.html',
      filename: 'index.html'
    })
  ],
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    }
  },
  devServer: {
    static: {
      directory: path.join(__dirname, 'dist')
    },
    compress: true,
    port: 8080,
    open: true
  }
};

view raw JSON →