Html-webpack-plugin: Adding custom attributes to injected scripts tags

Created on 4 Jan 2017  路  6Comments  路  Source: jantimon/html-webpack-plugin

Hi,

Now webpack is injecting this in my index.html after npm run build

<script type="text/javascript" src="./static/js/manifest.0298f1f656f4d6c242e0.js"></script>

I want to add a class and also change the attribute src to data-src, how I can do that?

Most helpful comment

Thanks! It worked. As you said I leaved inject: false, renamed my template from index.html to index.ejs

and then where I want my scripts to load with custom attributes I did this

<% for (key in htmlWebpackPlugin.files.js) { %>
    <script type="text/javascript" data-src="<%= htmlWebpackPlugin.files.js[key] %>"></script>
<% } %>

All 6 comments

Set inject:false and use the template options

Please, can you give me a hint in how to do it?

I'm searching and searching but I can't find an example.

If I put inject:false the css and scripts doesn't appear in the final index.html

What should I put in my index.html?

Thanks! It worked. As you said I leaved inject: false, renamed my template from index.html to index.ejs

and then where I want my scripts to load with custom attributes I did this

<% for (key in htmlWebpackPlugin.files.js) { %>
    <script type="text/javascript" data-src="<%= htmlWebpackPlugin.files.js[key] %>"></script>
<% } %>

Cool 馃憤

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.

Was this page helpful?
0 / 5 - 0 ratings