webpack-mkcert

raw JSON →
1.0.3 verified Sat Apr 25 auth: no javascript

Webpack plugin that provides HTTPS certificates for local development using mkcert. Version 1.0.3, maintained with monthly releases. Unlike manual certificate setups, it automates mkcert download and CA installation, supports multiple hosts (localhost, 127.0.0.1, custom domains), and includes a China mirror for faster downloads. Ships TypeScript types and requires Node >=16.

error Error: Cannot find module 'webpack-mkcert'
cause Package not installed or import path incorrect.
fix
Run 'npm install webpack-mkcert' and use ES import: import webpackMkcert from 'webpack-mkcert'.
error TypeError: webpackMkcert is not a function
cause Using require() instead of default import.
fix
Use 'import webpackMkcert from 'webpack-mkcert'' (ESM) instead of 'const webpackMkcert = require('webpack-mkcert')'.
error Error: mkcert binary not found. Please install mkcert or set mkcertPath.
cause Automatic download failed or network issue.
fix
Set option 'source: 'coding'' for China mirror, or provide 'mkcertPath' to a local mkcert binary.
error Error: self signed certificate in certificate chain
cause The generated certificate is not trusted by the system.
fix
Run 'mkcert -install' to install the local CA root certificate, or use the plugin's mkcert installation.
gotcha The plugin must be used asynchronously; it returns a Promise.
fix Use async/await or .then() when calling webpackMkcert().
gotcha On first run, mkcert binary is downloaded automatically. This may fail in restrictive networks.
fix Set source to 'coding' for China mirror or provide a local mkcertPath.
deprecated The force option is deprecated in favor of always regenerating if needed.
fix Remove force option; certificates are auto-regenerated when hosts change.
gotcha The plugin must be called inside an async function; it cannot be used in a synchronous config.
fix Wrap the config export in an async function as shown in the quickstart.
breaking Version 1.0.0 changed the return format from { cert, key } strings to an object with Buffer properties.
fix Update your code to handle Buffer objects if you process them directly.
gotcha The mkcert binary is saved to a plugin-specific data directory; uninstall via mkcert -uninstall.
fix To remove CA certificates, run mkcert -uninstall manually.
npm install webpack-mkcert
yarn add webpack-mkcert
pnpm add webpack-mkcert

Configures a Vue CLI Webpack dev server to use HTTPS with certificates generated by mkcert.

// webpack.config.js (ESM)
import webpackMkcert from 'webpack-mkcert';

export default async () => {
  const https = await webpackMkcert({
    source: 'coding',
    hosts: ['localhost', '127.0.0.1'],
    force: false
  });

  return {
    devServer: {
      server: {
        type: 'https',
        options: {
          host: 'localhost',
          ...https
        }
      }
    }
  };
};