Update 1: Fixed syntax issue that caused my initial build errors.
Update 2: Found my own solution using a Webpack plugin. See the accepted solution.
I want to add some custom HTML comments in the public/index.html
during a build. I added something like this:
<!--
My Application
Version: <%= VUE_APP_VERSION %>
Build date: <%= VUE_APP_BUILD_DATE %>
-->
In my vue.config.js
, I've set VUE_APP_VERSION
and VUE_APP_BUILD_DATE
accordingly:
let today = new Date().toLocaleDateString(undefined, {
year: 'numeric',
month: '2-digit',
day: '2-digit'
})
process.env.VUE_APP_VERSION = require('./package.json').version
process.env.VUE_APP_BUILD_DATE = today
But when I actually build (npm run build
), the comments are removed completely and everything is minimized.
How do I preserve my comments?