My future web app is a part of the firmware. The firmware is supposed to be built for a lot of devices. For each of them there is a profile with configuration parameters. I need to clean up app's html templates from unnecessary features. The reason i want to do it at build time is the size of firmware. So, i want to replace all v-if
statements that use profile
object with constant values.
For example, this html
<div v-if="profile.feature1"></div>
is supposed to be replaced with this:
<div v-if="false"></div>
After this the whole div tag will be removed as dead.
As far as I understand, I can do a similar thing with js by writing a plugin for rollup
, but with html... no idea.
In previous version of this web app i used gulp
plugin as a part of html processing pipeline.
Which options do i have if i migrate to quasar?
I googled the subject but with no success.
PS:
I figured out that i have no need to write rollup
plugin in case of js.
According to docs:
When compiling your website/app, if () branches depending on process.env are evaluated, and if the expression is false, they get stripped out of the file.
That's a good news. But i still don't know how to access process.env
in templates and would it be stripped like js.
Update:
I found another way to preprocess sources. There is rawDefine
property in quasar.config.js
. AFAIK it's based on the same define
vite
's feature. It's allows me to use SOME_FEATURE
constants in source code directly without process.env
. It didn't give the answer for templates by itself, but i looked at what came to define
plugin as input and saw _ctx.SOME_FEATURE
. So, now i can add _ctx.
prefixed version of every constant in rawDefine
to make it replaced by define
plugin.
The problems that i still have:
- I don't know how reliable it is. It looks like a workaround.
- The tag with
v-if="SOME_FEATURE"
is stripped, but if the tag refers to a component and that component isn't used anywhere else it's still here. On other hand, if i replacev-if="SOME_FEATURE"
tov-if="false"
then both (the tag of the component and the component itself) are removed.