Skip to content

Instantly share code, notes, and snippets.

@ChaseH88
Last active October 13, 2020 10:22
Show Gist options
  • Select an option

  • Save ChaseH88/6cc2ce4a4369dd8bc947b29b1f696cd9 to your computer and use it in GitHub Desktop.

Select an option

Save ChaseH88/6cc2ce4a4369dd8bc947b29b1f696cd9 to your computer and use it in GitHub Desktop.
/**
* Extract specific files from HTMLWebpackPlugin
* https://webpack.js.org/plugins/html-webpack-plugin/
*/
<% function extractHash(pattern){ %>
<% return Object.values(htmlWebpackPlugin.files.js).filter(function(val) { %>
<% return val.match(pattern) %>
<% }); %>
<% } %>
/**
* @example
*/
<script src="<%=extractHash(/\/js\/appLoading-\w+\.js/)%>"></script>
/**
* Expected Output:
* /js/appLoading38978911087464.js
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment