How do I dynamically load scripts based on the environment in the Webpack-packaged project html?

for example, I want to dynamically load Google Analytics based on the environment in index.html. The development environment does not introduce its script, and the production environment introduces its script.

I tried to read the process.env attribute, but unlike the js file within the project, I couldn"t read it in index.html.

is there a solution?

Jun.30,2022

If

has html-webpack-plugin , it would be nice to add a judgment.

<%=process.env.NODE_ENV==='production' ? '<script src="xxx.js"></script>' : ''%>

A simpler approach, you can use different index.html in different environments, which is always easy to do.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3cd7c-34712.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3cd7c-34712.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?