I don't think this is supported out-of-the-box in parcel v2, but it could be accomplished relatively easily with a custom namer plugin
Here's some code that will work:
import { Namer } from "@parcel/plugin";
import path from "path";
export default new Namer({
name({ bundle }) {
if (bundle.type === "html") {
const filePath = bundle.getMainEntry()?.filePath;
if (filePath) {
let baseNameWithoutExtension = path.basename(filePath, path.extname(filePath));
// See: https://parceljs.org/plugin-system/namer/#content-hashing
if (!bundle.needsStableName) {
baseNameWithoutExtension += "." + bundle.hashReference;
}
return `${baseNameWithoutExtension}.htm`;
}
}
// Returning null means parcel will keep the name of non-html bundles the same.
return null;
},
});
The easiest way to hook this plugin up with parcel without publishing a separate package is to use yarn's link protocol.
You'd structure your project like this:
project
├── .parcelrc
├── package.json
├── src
│ └── index.html
└── parcel-namer-htm
├── package.json
└── src
└── HtmNamer.js <-- the code above
Your main package.json
would link to your parcel-namer-htm
folder like this:
{
"name": "my-project",
"dependencies": {
"parcel": "^2.0.0",
"parcel-namer-htm": "link:./parcel-transformer-foo"
}
}
Your .parcelrc
file would look like this:
{
"extends": "@parcel/config-default",
"namers": ["parcel-namer-htm", "..."]
}
And the parcel-namer-htm/package.json
would look like this:
{
"name": "parcel-namer-htm",
"main": "src/HtmNamer.js",
"engines": {
"node": ">= 12.0.0",
"parcel": "^2.0.0"
},
}