TL;DR: How can I tell react build script to leave parts of code untouched?
I made an app with "create-react-app". I am using the standard "npm run build" command to make my production build.
In the index.html file I included a Google Tag Manager and Google Optimize snippet.
On build, the script minifies those in a way that prevents them from working.
So right now, every time I "build", I have to overwrite the minified parts with the original snippets manually. That is - of course - super unhandy.
How can I tell the build script to leave these parts alone? I browsed the docu without success...
Thanks for any help!
NORMAL (UNMINIFIED) CODE:
<!-- Google Optimize async hide -->
<style>.async-hide { opacity: 0 !important} </style>
<script>
(function(a,s,y,n,c,h,i,d,e){
s.className+=' '+y;
h.end=i=function(){
s.className=s.className.replace(RegExp(' ?'+y),'')};
(a[n]=a[n]||[]).hide=h;setTimeout(function(){
i();h.end=null
},c);
})
(window,document.documentElement,'async-hide','dataLayer',4000,{'GTM-ABCDEF12':true});
</script>
<!-- Google Tag Manager -->
<script>
(function(w,d,s,l,i){
w[l]=w[l]||[];w[l].push({
'gtm.start': new Date().getTime(),
event:'gtm.js'});
var
f=d.getElementsByTagName(s)[0],
j=d.createElement(s),
dl=l!='dataLayer'?'&l='+l:'';
j.async=true;
j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;
f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-ABCDEF12');</script>
<!-- End Google Tag Manager -->
MINIFIED CODE:
<style>.async-hide{opacity:0!important}</style>
<script>!function(e,n,a,c,t,d,s,i,l){
n.className+=" "+a,d.end=s=function(){
n.className=n.className.replace(RegExp(" ?"+a),"")
},
(e[c]=e[c]||[]).hide=d,setTimeout(function(){
s(),d.end=null
},4e3)
}(window,document.documentElement,"async-hide","dataLayer",0,{"GTM-ABCDEF12":!0})
</script>
<script>
!function(e,t,a,n,g){
e[n]=e[n]||[],e[n].push({
"gtm.start":(new Date).getTime(),
event:"gtm.js"
});
var m=t.getElementsByTagName(a)[0],
r=t.createElement(a);
r.async=!0,
r.src="https://www.googletagmanager.com/gtm.js?id=GTM-ABCDEF12",
m.parentNode.insertBefore(r,m)
}(window,document,"script","dataLayer")
</script>