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

Support for nested objects

Open elliottcrush opened this issue 8 years ago • 4 comments

Can I submit a PR to allow for an object of objects to be passed to the interpolate plugin?

This would allow me to do

const config = {
'foo': 'bar',
'bar': {
 'foofoo': 'barbar'
 }
}

And then in my .html file

    <link href="//%bar.foofoo%/assets/css.css" rel="stylesheet" type="text/css"></link>

elliottcrush avatar Nov 20 '17 14:11 elliottcrush

Maybe we can just make it support custom template engine?

For your use case you can just pass that config as html-webpack-plugin's options:

new HtmlWebpackPlugin({
  config
})

egoist avatar Nov 20 '17 14:11 egoist

How do you mean?

When I pass in nested objects aka config above I can't access those properties by doing bar.foofoo in the HTML template. Could you elebarote a bit more about how that would work please?

elliottcrush avatar Nov 20 '17 14:11 elliottcrush

I mean this plugin is totally unnecessary, you can directly access the options of html-webpack-plugin instance in your template:

// webpack config
new HtmlWebpackPlugin({
  config,
  template: './some/index.template.html'
})

Then in your template index.template.html:

// html-webpack-plugin uses ejs template syntax by default
<%= htmlWebpackPlugin.options.config.foo.bar %>

egoist avatar Nov 20 '17 14:11 egoist

Oh I didn't know that was possible. Thanks for that @egoist

elliottcrush avatar Nov 20 '17 15:11 elliottcrush