如何使用 webpack 注入内部版本号? [英] How can I inject a build number with webpack?

查看:42
本文介绍了如何使用 webpack 注入内部版本号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向我的项目注入内部版本号和版本信息,因为它是用 webpack 构建的.例如,让我的代码可以执行以下操作:

I'd like to inject a build number and version information to my project as it's built with webpack. For example, so that my code can do something like:

var buildInfo = require("build-info");

在构建时生成 build-info 模块的最佳方法是什么?

What would be the best way to generate that build-info module at build time?

推荐答案

您可以使用 DefinePlugin 这将使您的构建信息与您的代码内联可用:

You can use the DefinePlugin that will make your build info available inlined with your code:

配置

new webpack.DefinePlugin({
   __VERSION__: JSON.stringify('12345')
})

应用代码

console.log(__VERSION__);

这篇关于如何使用 webpack 注入内部版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆