jharris4 / html-webpack-tags-plugin

lets you define html tags to inject with html-webpack-plugin
MIT License
256 stars 31 forks source link

why I update html-webpack-include-assets-plugin to 1.0.9, include assets will be append several times #55

Closed sailormillet closed 4 years ago

sailormillet commented 4 years ago

hello, @jaridmargolin ,In the previous version, html-webpack-include-assets-plugin@1.0.7, everything works fine. My colleague update the plugin, I see some errors. include assets will be append several times. this is code:

new HtmlWebpackIncludeAssetsPlugin({
    assets: ['css/no-public-path.min.css', 
                  'scripts/libraries/vendor.js',
                  'scripts/libraries/vendor2.js'],
    append: false,
  })

append the following into the index template html like this

<head>
  <link rel="icon" href="css/no-public-path.min.css"/>
  <link rel="icon" href="css/no-public-path.min.css"/>
  <link rel="icon" href="css/no-public-path.min.css"/>
</head>
<body>
  <script type="text/javascript" src="scripts/libraries/vendor.js"></script>
  <script type="text/javascript" src="scripts/libraries/vendor2.js"></script>
  <script type="text/javascript" src="scripts/libraries/vendor.js"></script>
  <script type="text/javascript" src="scripts/libraries/vendor2.js"></script>
  <script type="text/javascript" src="scripts/libraries/vendor.js"></script>
  <script type="text/javascript" src="scripts/libraries/vendor2.js"></script>
</body>

should I use html-webpack-tags-plugin replace html-webpack-include-assets-plugin, they are the same plugin or different

jharris4 commented 4 years ago

should I use html-webpack-tags-plugin replace html-webpack-include-assets-plugin, they are the same plugin or different

html-webpack-tags-plugin is the newer version, it works mostly the same except drops support for node versions < 8, and changes the configuration syntax.

I would recommend that you update to use the newer version, and for the configuration you posted above, change it to:

new HtmlWebpackTagsPlugin({
  tags: [
    'css/no-public-path.min.css', 
    'scripts/libraries/vendor.js',
    'scripts/libraries/vendor2.js'
  ],
  append: false,
})

As for the assets appearing twice, I suspect that you may be including the plugin 2 times in your webpack config. Please double check that, and if you still see the issue, it would be helpful if you could share your complete webpack configuration.

sailormillet commented 4 years ago

should I use html-webpack-tags-plugin replace html-webpack-include-assets-plugin, they are the same plugin or different

html-webpack-tags-plugin is the newer version, it works mostly the same except drops support for node versions < 8, and changes the configuration syntax.

I would recommend that you update to use the newer version, and for the configuration you posted above, change it to:

new HtmlWebpackTagsPlugin({
  tags: [
    'css/no-public-path.min.css', 
    'scripts/libraries/vendor.js',
    'scripts/libraries/vendor2.js'
  ],
  append: false,
})

As for the assets appearing twice, I suspect that you may be including the plugin 2 times in your webpack config. Please double check that, and if you still see the issue, it would be helpful if you could share your complete webpack configuration.

thanks for your reply. I check my config. and find the config is right. maybe my project is Multi Page Application and I found that the assets is always equal to the project’s application pages. so I check differenthtml-webpack-tags-plugin version's code. find something was different.

image

so I think html-webpack-tags-plugin versions > 1.0.6, the project is Multi Page Application. will see the issue.

jharris4 commented 4 years ago

@sailormillet it's quite difficult to help debug your issues without seeing a more complete webpack config. Without more detail, the only things I can suggest are:

jharris4 commented 4 years ago

@sailormillet Hopefully you've resolved your problems. I'm closing the issue, but feel free to open a new one if you're still having trouble!

the-simian commented 4 years ago

I experienced this exact issue when using dependencies that used the older html-webpack-include-assets-plugin. upgrading to the tags version fixed it for me, but a lot of plugins out there still use the old one.