There are two solutions.
1. Imports Contract
This is what I'm doing in my personal contracts library
// SPDX-License-Identifier: Unlicense pragma solidity >=0.8.4; import "@prb/math/contracts/PRBMathUD60x18.sol";
As you can see, all this is doing is importing the external contract from an npm package, such that Hardhat will pick it up and generate an artifact for it.
2. Use hardhat-dependency-compiler
It's a Hardhat plugin developed by Nick Barry. Install it:
yarn add --dev hardhat-dependency-compiler
And add the following to your Hardhat config file:
dependencyCompiler: { paths: [ 'path/to/external/Contract.sol', ], }
For what it's worth, I prefer the first solution. It's less verbose in that I don't add yet-another-node-package to my package.json file.