Html-webpack-plugin: Conditional codes in html template

Created on 24 May 2015  路  12Comments  路  Source: jantimon/html-webpack-plugin

Hi @ampedandwired,

Is it possible to have conditional codes, something like below:

if (o.webpackconfig.Production)
{
 <script type="text/javascript" src="{%=o.webpackconfig.UrlInProduction %}"></script>
}
else{
 <script type="text/javascript" src="{%=o.webpackconfig.urlInDevelopment%}"></script>
}

thanks

Most helpful comment

@eventhough They've changed it in 2.X
Now it's the ejs style - <% if (htmlWebpackPlugin.options.environment.production){ %>

Hope it helps, I've spent 2 hours finding this info out for myself after seeing no answer in this issue

All 12 comments

I think I found the solution. It is just normal Javscript as long as you enclose them by {%}.

{% if (o.webpackconfig.Production) { %}
 <script type="text/javascript" src="{%=o.webpackconfig.UrlInProduction %}"></script>
{% } %}
{% else { %}
<script type="text/javascript" src="{%=o.webpackconfig.urlInDevelopment%}"></script>
{% } %}

@KhoaSydney How did you set the o.webpackconfig.Production flag? Could you share your HtmlWebpackPlugin configuration?

@eventhough They've changed it in 2.X
Now it's the ejs style - <% if (htmlWebpackPlugin.options.environment.production){ %>

Hope it helps, I've spent 2 hours finding this info out for myself after seeing no answer in this issue

@shairez can you share your config? I can't seem to get options.environment working for me

@shairez nvm, got it working =)

@Restuta what did you do to get this working?

In most cases inject:true will solve this for you

@jantimon I have inject: 'body'

so does that only allow templating in body?

Inject:true and inject:body is the same (and it's also the default if you don't specify inject) it will inject all link and script tags for you so that you can use the same template for dev and production

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

Related issues

amorphius picture amorphius  路  3Comments

ghaiklor picture ghaiklor  路  3Comments

MatthewKosloski picture MatthewKosloski  路  3Comments

NeverwinterMoon picture NeverwinterMoon  路  3Comments

lonelydatum picture lonelydatum  路  3Comments