How to inject Webpack build hash to application code

后端 未结 5 1335
花落未央
花落未央 2021-01-04 08:29

I\'m using Webpack\'s [hash] for cache busting locale files. But I also need to hard-code the locale file path to load it from browser. Since the file path is altered with [

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-04 09:16

    You can pass the version to your build using webpack.DefinePlugin

    If you have a package.json with a version, you can extract it like this:

    const version = require("./package.json").version;
    

    For example (we stringified the version):

    new webpack.DefinePlugin({
        'process.env.VERSION': JSON.stringify(version)
    }),
    

    then in your javascript, the version will be available as:

    process.env.VERSION
    

提交回复
热议问题