jantimon/html-webpack-plugin

Changelog + Migration guide

mmakarin opened this issue · 7 comments

Please update changelog with every release. Also there is no migration guide for 2.x.

Open for pull requests.

For the record, I had to upgrade from 1.6.2. My custom template was:

<!DOCTYPE html>
<html{% if(o.htmlWebpackPlugin.files.manifest) { %} manifest="{%= o.htmlWebpackPlugin.files.manifest %}"{% } %}>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{%=o.htmlWebpackPlugin.options.title || 'Webpack App'%}</title>
    {% if (o.htmlWebpackPlugin.files.favicon) { %}
    <link rel="shortcut icon" href="{%=o.htmlWebpackPlugin.files.favicon%}">
    {% } %}
    {% for (var css in o.htmlWebpackPlugin.files.css) { %}
    <link href="{%=o.htmlWebpackPlugin.files.css[css] %}" rel="stylesheet">
    {% } %}
</head>
<body>
{% for (var chunk in o.htmlWebpackPlugin.files.chunks) { %}
<script src="{%=o.htmlWebpackPlugin.files.chunks[chunk].entry %}"></script>
{% } %}
</body>
</html>

To upgrade I had to:

  • Modify the custom html template I had, replacing {% and %} for <% and %>
  • Also replace in the html template all instances of o.htmlWebpackPlugin for htmlWebpackPlugin
  • Remove all loops to inject files, as the plugin is already injecting them even without specifying the inject param.

The template ended up like this:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<% if (htmlWebpackPlugin.files.favicon) { %>
<link rel="shortcut icon" href="<%=htmlWebpackPlugin.files.favicon%>">
<% } %>
<title><%=htmlWebpackPlugin.options.title || 'Webpack App'%></title>
</head>
<body>
</body>
</html>

@Danita Thank you!

FYI you can now require directly in templates:

<link rel="apple-touch-icon" href="<%- require('../images/favicons/apple-icon-60x60.png') %>">

I gonna close this for now - feel free to add something if you want to add something to the migration document.

lock commented

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.