Javascript 如何在内部使用html网页包插件变量<;脚本>;?

Javascript 如何在内部使用html网页包插件变量<;脚本>;?,javascript,webpack,html-webpack-plugin,Javascript,Webpack,Html Webpack Plugin,我试图通过变量所在的html网页插件在标记内分配变量。 我可以很容易地在像title这样的html标记中使用它 我的html网页包插件看起来像: new HtmlWebpackPlugin({ filename: config.build.index, template: 'index.html', inject: true, applicationId : process.env.APPLICATION_ID ?process.env.APPL

我试图通过变量所在的html网页插件在
标记内分配变量。 我可以很容易地在像title这样的html标记中使用它

我的html网页包插件看起来像:

new HtmlWebpackPlugin({
      filename: config.build.index,
      template: 'index.html',
      inject: true,
      applicationId : process.env.APPLICATION_ID ?process.env.APPLICATION_ID : 1,
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeAttributeQuotes: false
        // more options:
        // https://github.com/kangax/html-minifier#options-quick-reference
      },
      // necessary to consistently work with multiple chunks via CommonsChunkPlugin
      chunksSortMode: 'dependency'
    }),
我想在index.html页面上使用变量applicationId,并使用以下脚本:

<script type="text/javascript">
      var xhr = new XMLHttpRequest();
      xhr.onreadystatechange = function() {
        if (xhr.readyState == XMLHttpRequest.DONE) {
          document.write(xhr.responseText);
        }
      };
     var appId = <%= htmlWebpackPlugin.options.applicationId %>;
   xhr.open("GET","https://somesite.com/NavigationApi/api/content/get?applicationId=" + appId,false);
      xhr.send(null);
    </script>

var xhr=new XMLHttpRequest();
xhr.onreadystatechange=函数(){
if(xhr.readyState==XMLHttpRequest.DONE){
document.write(xhr.responseText);
}
};
var-appId=;
xhr.open(“GET”https://somesite.com/NavigationApi/api/content/get?applicationId=“+appId,false);
xhr.send(空);

您可以设置一个隐藏的输入,并在那里设置
appId
,然后您可以使用javascript检索该值(确保在jquery的
onload
事件中这样做,或者如果您想使用vanilla JS,请使用),希望这能有所帮助。

当前将
appId
设置为什么?