0

I am using html-webpack-plugin to process html files.
I need to remove some parts before i export for server. I found a couple plugins to do this but they are outdated or doesn't work with webpack 4.

This is my config for html-webpack-plugin.

enter image description here

I marked the parts i wanted to remove like this.

<!--deletestart--> 
  code to be removed.
<!--deleteend-->

enter image description here

Is there any working plugin or a way to do this with webpack 4? Thanks.

atilkan
  • 4,527
  • 1
  • 30
  • 35
  • 1
    Maybe writing your own little plugin is an option? `html-webpack-plugin` provides a hook for that. https://github.com/jantimon/html-webpack-plugin#events – lukas-reineke Mar 08 '18 at 14:42
  • I suggested an update for existing plugin. And the author quickly made the change. Thanks anyway. html-webpack-plugin-remove – atilkan Mar 08 '18 at 14:44
  • 1
    Good. But I also just remembered, there is another way without a plugin. If you use `html-webpack-plugin`s templating and `<% if(foo) { %> html <% } %>` – lukas-reineke Mar 08 '18 at 14:48
  • Thanks. I will give it a shot. – atilkan Mar 09 '18 at 12:07

1 Answers1

0

I suggested an update for existing plugin. And the author quickly made the change. Thanks.

html-webpack-plugin-remove

https://github.com/alexblunck/html-webpack-plugin-remove

I can use it easily like this.

new HtmlPluginRemove(/<!--deletestart-->[\s\S]*<!--deleteend-->/gi),
atilkan
  • 4,527
  • 1
  • 30
  • 35