arthurbergmz / webpack-pwa-manifest

Progressive Web App Manifest Generator for Webpack, with auto icon resizing and fingerprinting support.
MIT License
514 stars 93 forks source link

Add support for <head>-less templates #126

Closed kmohrf closed 2 years ago

kmohrf commented 4 years ago

Hi,

this PR changes the hook used by the tapable generator from beforeEmit that modifies the generated HTML to alterAssetTags/alterAssetTagGroups (depending on the html-webpack-plugin version), that inserts manifest tags into the data structure provided by the html-webpack-plugin.

This makes it possible to use the webpack-pwa-manifest plugin for templates without a head tag. Until now that was not possible, because the manifest tags would be inserted before the closing head tag through string replacement. The following html-webpack-plugin configuration would produce a <head>-less template:

{
  inject: false,
  templateContent ({ htmlWebpackPlugin }) {
    const tags = [].concat(
      htmlWebpackPlugin.tags.headTags,
      htmlWebpackPlugin.tags.bodyTags
    )
    return tags.join('\n')
  }
}

This is helpful in scenarios where the generated HTML is loaded into an existing head tag. In my case I include the generated HTML into my python-django application via the include mechanism of the template engine.

This PR also changes a few other things. I’m not sure if they should end up in the same pull request, but YMMV:

NOTE: I have not added tests for this because I’m not sure how to test the behaviour for html-webpack-plugin v4, as v3 is the one installed by dev-dependencies. I can confirm it’s working, because I myself use v4 in my project, but that is more like anecdotal evidence :). Feel free to make a suggestion on how to solve this and I’ll look into it.

Cheers

Konrad

kmohrf commented 4 years ago

ping @arthurconexia :)

kmohrf commented 4 years ago

or maybe ping @arthurbergmz?

kmohrf commented 3 years ago

@arthurbergmz any chance?

kmohrf commented 3 years ago

@arthurbergmz ping

kmohrf commented 2 years ago

Closing this, because I’ve migrated away from webpack and want to get rid of this PR in my PR overview :). Feel free to merge the changes if you find the time.