html-webpack-plugin icon indicating copy to clipboard operation
html-webpack-plugin copied to clipboard

specify the location of the assets inject to?

Open hzdorian opened this issue 10 years ago • 4 comments

In my opinion, the template decides the main layout for the .html documents that created.

so,

if the HtmlWebpackPlugin providers an especial mark (e.g <!-- webpack:javascript -->) in the template, and then replace the <script> tags all here. Now, I think the development experience will be much better!

Therefore, I can code my templates like this:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8" />
    <title>title</title>
    <!-- webpack:css -->
    <script type="text/javascript">
    var F = {
        // global config here.
    };
    </script>
</head>
<body>
    <div class="loading"></div>
    <div class="app"></div>
    <!-- webpack:javascript -->

    <script type="text/javascript">
    // post logic here
    </script>
</body>
</html>

hzdorian avatar Jul 18 '16 16:07 hzdorian

this won't solve all use cases so just turn off injection and add the assets by yourself using the template variables

jantimon avatar Jul 19 '16 15:07 jantimon

Er! I got it, I agree with u. Maybe template engine would work well.

hzdorian avatar Jul 19 '16 16:07 hzdorian

Just to help others who find this.
Use this to specify the place of the output in your template:

<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
<script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
<% } %>

From https://github.com/jaketrent/html-webpack-template/blob/86f285d5c790a6c15263f5cc50fd666d51f974fd/index.html

escapedcat avatar Jan 23 '17 03:01 escapedcat

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.

lock[bot] avatar May 31 '18 17:05 lock[bot]