如何在html中传递webpack环境变量? [英] How can i pass webpack environment variables in html?
本文介绍了如何在html中传递webpack环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在处理时间内(而不是浏览器中的运行时)获取/访问webpack ENV变量? webpack.DefinePlugin(...)
似乎无法在html文件中工作,我无法访问主index.html
How can i get / access webpack ENV variables during process time (not runtime in browser) ? the webpack.DefinePlugin(...)
doesn't seem to work in html files, i don't have access to ENV variables in the main index.html
任何解决方案吗?
推荐答案
您可以使用 html -webpack-plugin .您将必须使用.ejs或其他模板语言,然后使用
You can use html-webpack-plugin. You will have to use .ejs or some other template language and then use like that
new HtmlWebpackPlugin({
template: './src/public/index.ejs',
inject: 'body',
environment: process.env.NODE_ENV
}),
在index.ejs中
in index.ejs
<body class="<%= htmlWebpackPlugin.options.environment %>">
这篇关于如何在html中传递webpack环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文