Parcel should auto-add process.env to posthtml-expression locals
🙋 feature request
I'm trying to include an analytics script ONLY in production. I want to use a .posthtmlrc file and not a .posthtmlrc.js file to take advantage of all the caching. If parcel could inject process.env into the locals of posthtml-expression I would be very pleased :)
🤔 Expected Behavior
I want to be able to use process.env in my index.html file
😯 Current Behavior
My current setup is:
// .posthtmlrc.js
module.exports = {
plugins: {
'posthtml-include': {},
'posthtml-expressions': {
locals: {
NODE_ENV: process.env.NODE_ENV,
},
},
},
};
<!-- index.html -->
<if condition="NODE_ENV === 'production'">
<script src="https://cdn.usefathom.com/script.js" defer></script>
</if>
💁 Possible Solution
Auto-inject process.env into index.html so I can do:
<if condition="process.env.NODE_ENV === 'production'">
<script src="https://cdn.usefathom.com/script.js" defer></script>
</if>
Maybe I should take this up with posthtml. If so, don't mind me. Thanks! Love parcel and use it extensively for new sideprojects like valentineroulette.com
Looking for the exact same use case! For now I can only think of the config as javascript route...
Another workaround is to create a custom posthtml plugin that can modify your dom tree. That's actually working better for me in my use case.