jaketrent / html-webpack-template

a better default template for html-webpack-plugin
MIT License
830 stars 139 forks source link

scripts option broken when use cli arguments #46

Closed HairyRabbit closed 6 years ago

HairyRabbit commented 7 years ago

When I use html-webpack-template with cli argumnet like:

"start": "webpack --plugin=html-webpack-plugin?template=./node_modules/html-webpack-template/index.ejs,mobile=true,inject=false,appMountId=app,scripts=vendor.js"

It's will render follow script tags:

<script src="v" type='text/javascript'><script>
<script src="e" type='text/javascript'><script>
<script src="n" type='text/javascript'><script>
<script src="d" type='text/javascript'><script>
<script src="v" type='text/javascript'><script>
<script src="o" type='text/javascript'><script>
<script src="r" type='text/javascript'><script>
<script src="." type='text/javascript'><script>
<script src="j" type='text/javascript'><script>
<script src="s" type='text/javascript'><script>
TAGC commented 7 years ago

Just a wild stab in the dark but "scripts" looks like something that would accept an array. Have you tried scripts=[vendor.js] instead? Or however you specify arrays as a CLI argument string.

HairyRabbit commented 7 years ago

Yeap, [vendor.js] also output split by char. I modifed the template like:

<% if (Array.isArray(htmlWebpackPlugin.options.scripts)) { %>
    <% for (item of htmlWebpackPlugin.options.scripts) { %>
    <% if (typeof item === 'string' || item instanceof String) { item = { src: item, type: 'text/javascript' } } %>
    <script<% for (key in item) { %> <%= key %>="<%= item[key] %>"<% } %>></script>
    <% } %>
    <% } else { %>
    <% for (item of htmlWebpackPlugin.options.scripts.split(';')) { %>
    <% if (typeof item === 'string' || item instanceof String) { item = { src: item, type: 'text/javascript' } } %>
    <script<% for (key in item) { %> <%= key %>="<%= item[key] %>"<% } %>></script>
    <% } %>
<% } %>

It's supports simple multi scripts name read from cli args.

scripts=foo.js;bar.js
jaketrent commented 7 years ago

Any interest in adjustments here at this point?

jaketrent commented 6 years ago

I don't know if this is still broken or not. It's definitely a stagnant issue. If there is still interest here, please submit a PR, and we'll get it fixed for the cli case if needed.