Webpack packaged vue multi-page application, how to choose whether to introduce some statistical codes according to the different development environment

recently, a multi-page application packaging vue is being built with webpack. Some statistical codes (mainly the introduction of js) choose whether to add to the page according to the difference between the test environment and the production environment. The test environment and the production environment have been distinguished by the value of process.env.NODE_ENV, but they still do not know whether to load the statistical js according to the environment

.
new webpack.DefinePlugin({
    "process.env.NODE_ENV": JSON.stringify("test")
})

to put it more generally, I don"t know how to choose whether to load a js based on the value of a variable

Mar.09,2021

in your main.js, judge the NODE_ENV, and then dynamically create the script tag, and add the js you need to introduce

.
Menu