Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Plugins: Index Hooks #182

Closed
1 of 5 tasks
thescientist13 opened this issue Aug 26, 2019 · 0 comments
Closed
1 of 5 tasks

[RFC] Plugins: Index Hooks #182

thescientist13 opened this issue Aug 26, 2019 · 0 comments
Assignees
Labels
Plugins Greenwood Plugins RFC Proposal and changes to workflows, architecture, APIs, etc v0.4.0 Plugins and Packages
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Aug 26, 2019

Type of Change

  • New Feature Request
  • Documentation / Website
  • Improvement / Suggestion
  • Bug
  • Other (please clarify below)

Summary

Taken from a comment in #17 (comment) in regards to a general discussion around the API and capturing the specific action item re: the hooks plugin type here.

Details

In particular index.html provides the most opportunity right now as things like polyfills, analytics, and PWA features like manifest.json and ServiceWorkers need to be installed in a global scope and /or unbundled. These would essentially be pre-defined find / replace hooks in index.html.

Usage

A great example use case is injecting Google Analytics into index.html.

In Greenwood's index.html we would add this marker

  ...

  <%= htmlWebpackPlugin.options.hookGreenwoodAnalytics %>

Then in Greenwood config, you tap into it like this:

module.exports = {
  title: 'My App'

  ...

  plugins: [{
    type: 'hook',
    provider: (compilation) => {
      // you can access things like config, context if you need from compilation
      return {
        hookGreenwoodAnalytics: `
          <!-- Google Analytics -->
          <script>
            window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
            ga('create', 'UA-XXXXXXX', 'auto');
            ga('send', 'pageview');
          </script>
          <script async src='https://www.google-analytics.com/analytics.js'></script>
          <!-- End Google Analytics -->
        `
      ]
    }
  }]
}

The Greenwood plugin equivalent would essentially just wrap all of this for a user and just ask for analyticsId.

It should be noted that if these specific hook types are too limiting (we should support a basic set of common hooks), users can just make their own index.html and configure all of these Greenwood hooks themselves (if they wanted) or just create their own.

@thescientist13 thescientist13 added RFC Proposal and changes to workflows, architecture, APIs, etc Plugins Greenwood Plugins labels Aug 26, 2019
@thescientist13 thescientist13 added this to the MVP milestone Aug 26, 2019
@thescientist13 thescientist13 self-assigned this Aug 26, 2019
@thescientist13 thescientist13 changed the title [RFC] Plugins: Template Hooks [RFC] Plugins: Index Hooks Sep 5, 2019
@thescientist13 thescientist13 added the v0.4.0 Plugins and Packages label Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Plugins Greenwood Plugins RFC Proposal and changes to workflows, architecture, APIs, etc v0.4.0 Plugins and Packages
Projects
None yet
Development

No branches or pull requests

1 participant