// based on https://gist.github.com/necolas/1025811
(function(doc) {
  let js,
    fjs = doc.getElementById('bundle'),
    add = function(url, id) {
      if (doc.getElementById(id)) {return;}
      js = doc.createElement('script');
      js.src = url;
      id && (js.id = id);
      fjs.parentNode.insertBefore(js, fjs);
    };
<% for (let chunk in htmlWebpackPlugin.files.js) { %>
  <% if (compilation.compiler.outputFileSystem.constructor.name === 'MemoryFileSystem') { %>
    add('http://localhost:8080/<%= htmlWebpackPlugin.files.js[chunk] %>');
  <% } else { %>
    let root = fjs.src.substring(0, fjs.src.indexOf('dist'));
    add(root+'<%= htmlWebpackPlugin.files.js[chunk] %>');
  <% } %>
<% } %>
}(document));
