Where to find or how to set htmlWebpackPlugin.options.title in project created with vue cli 3?
Simply set the title
in the vue.config.js
inside the pages
configuration:
Don't forget to include <title><%= htmlWebpackPlugin.options.title %></title>
in your index.html
file for this to take effect. Also, if your use-case demands, runtime title updates can be achieved using Vue Meta or JavaScript. More on these below!
Dynamic Title: Chameleon Mode
Vue Meta: Metadata Management Guru
Vue Meta is a Japanese sensei for maintaining your Vue app's metadata! Install it (npm install vue-meta
), use it in your main.js
and define the metadata (including title) in your Vue components. Check how easy-peasy it is:
Now, you can define the title
in your components:
Vue Meta supports real-time updates and works well with SSR (Server-Side Rendering).
JavaScript: Native DIY Method
Need to change the title
at runtime? Just use JavaScript in your component's mounted
hook:
Static Title: Minimalist's Choice
Hardcoding: The Old School Style
You can set the title
directly in the public/index.html
file. It's as simple as:
Webpack Chain: For the Inner Control Freak
Alternatively, you can talk directly to Webpack via the chainWebpack
property:
Remember to restart your server after changes to vue.config.js
, as these don't support hot reloading.
Environmental Wisdom: A Title for Every occasion
Environment Variables: The Swiss Army Knife Approach
Keeping title
as an environment variable allows you to pivot it as per the respective environment. You need a .env
file in your project root -
like .env.development
or .env.production
. Set your titles like VUE_APP_TITLE=My Awesome App
and then access them within your app:
It's like having unique headgear for every occasion!
Don’t Forget UX: Titles Matter!
Ensure your title
reflects your app and makes sense for the user – remember, UX comes first!
Common Traps and Triumphs
Title Updates MIA
Changes not showing up after updates in vue.config.js
? Restart your server – hot reloading doesn't cover these changes.
Missing Dynamic Title Updates
Not seeing live title updates? Make sure you're using Vue Meta or setting document.title
in a mounted
hook.
Title Not Reading Environment Variable
Ensure environment variables carry the VUE_APP_
prefix to be accessible in your Vue app.
Was this article helpful?