Namer
A plugin type: Generates an output-filepath for a bundle
Namers accept a bundle and return a filepath for that bundle (this path has to be relative to bundle.target.distDir
).
import { Namer } from "@parcel/plugin";
export default new Namer({
async name({ bundle, bundleGraph, logger, options }) {
let name = yourNamingFunction(bundle);
if (!bundle.isEntry) {
name += "." + bundle.hashReference;
}
return name + "." + bundle.type;
},
});
Namers have complete freedom over the filepaths, but they should not include the hash in the filename if bundle.isEntry
is true.
ΒΆ Overriding names for specific bundles
The .parcelrc
file allows multiple namers to be specified. If some namer plugin returns null
, the next namer in the list is queried (and so on).
This makes it easy to override the filename for a specific bundle without having the copy the existing (general) namer.
ΒΆ Including a hash
If you want to include a hash in the filename that is based on the final bundle contents, insert bundle.hashReference
. This is an opaque value that will later on be replaced with the actual hash (since at this stage, there is no bundle content to generate the hash of).
ΒΆ Relevant API
Namer parcel/packages/core/types/index.js:1500
type Namer<ConfigType>Β = {|
loadConfig?: ({|
config: Config,
options: PluginOptions,
logger: PluginLogger,
|}) => Promise<ConfigType> | ConfigType,
name({|
bundle: Bundle,
bundleGraph: BundleGraph<Bundle>,
config: ConfigType,
options: PluginOptions,
logger: PluginLogger,
|}): Async<?FilePath>,
Return a filename/-path for bundle
or nullish to leave it to the next namer plugin.
|}