I'm using parcel.js to build a basic static website (so HTML, CSS and front end JS only, but node / npm / parcel.js used for building).
I'd like to set a favicon. What's the best / simplest way to do this?
At your <head>
tag at your html file you can use
<link rel="icon" href="favicon.ico" />
To have a favicon.ico
that will be used as a default favicon by browsers, it needs to be present without the hash that parcel.js generates. For that, you would have to not include it anywhere as parcel will then generate the file with a hash, i.e. favicon.f76ab27.ico
.
Try parcel-plugin-static-files-copy for this purpose. It copies files from one or more directories over to dist
. Try the following settings in package.json
:
{
"staticFiles": {
"staticPath": [
{
"staticPath": "path/to/static/files",
"watcherGlob": "**"
}
]
},
}
The trick is to not define a
staticPath
. Parcel will then copy the files to the root folder. All copied files will not have a hash appended.
You may want to add the parcel-plugin-robot plugin and add the favicon.ico file to the static/ directory.
This plugin will copy all files under static/
to the root dist/
directory, so this is also useful for robots.txt, humans.txt, browserconfig.xml and any other files that are expected at a website root directory by convention but that might not be referenced explicitly anywhere.