How can I inject a build number with webpack?

后端 未结 7 961
野的像风
野的像风 2021-01-30 10:38

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 bui         


        
相关标签:
7条回答
  • 2021-01-30 11:14

    I made a webpack loader that injects build information into an automatically generated file. You can find it on npm.

    Once you install it, you can use it like this:

    import buildinfo from "!webpack-plugin-buildinfo?gitHashShort&time!";
    console.log(
        `MyCoolProject v${buildinfo.gitHashShort} compiled at ${new Date(
            buildinfo.time
        ).toISOString()}`
    );
    

    For more information, visit the github repo.

    0 讨论(0)
提交回复
热议问题