Skip to content

Instantly share code, notes, and snippets.

@Grawl
Created August 10, 2019 06:21
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save Grawl/bd0096b49276934c807b4a74088b081c to your computer and use it in GitHub Desktop.
Save Grawl/bd0096b49276934c807b4a74088b081c to your computer and use it in GitHub Desktop.
Running Webpack Dev Server with HTTPS on developer machine using MKCERT
  1. Add local domain to /etc/hosts:

    127.0.0.1 my-project.dev

  2. Install mkcert

  3. Create certificate for this domain:

    ➜ mkcert my-project.dev
    
    Created a new certificate valid for the following names 📜
    - "my-project.dev"
    
    The certificate is at "./my-project.dev.pem" and the key at "./my-project.dev-key.pem"
  4. Copy certificate .dev.pem and the key .dev-key.pem to project folder:

    cp my-project.dev.pem path/to/my-project
    cp my-project.dev-key.pem path/to/my-project
  5. Add HTTPS options to Webpack Dev Server config:

    devServer: {
        host: 'my-project.dev',
        https: {
            key: fs.readFileSync('./my-project.dev-key.pem'),
            cert: fs.readFileSync('./my-project.dev.pem'),
        }
    },

Tested with:

  • webpack 4.28.4
  • webpack-dev-server 3.2.1
  • @vue/cli-service 3.5.3
  • mkcert 1.3.0 from Homebrew
  • macOS Mojave 10.14.6 (18G84)
@medmin
Copy link

medmin commented Jun 15, 2021

Thank you so much!!

@elVengador
Copy link

Thank you

@Grawl
Copy link
Author

Grawl commented Apr 4, 2022

@Nickz22
Copy link

Nickz22 commented May 5, 2022

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment