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

Server Plugin API #471

Merged
merged 5 commits into from
Feb 18, 2021
Merged

Conversation

hutchgrant
Copy link
Member

@hutchgrant hutchgrant commented Feb 3, 2021

Related Issue

Resolves #470

Summary of Changes

  • Adds a new Server Plugin API similar to resource plugins, similar plugin definition
  • Utilizes ServerInterface
  • Plugins declared with type: "server"
  • develop.js command plugin will call start() function from plugin when running greenwood in development mode
  • livereload is used as an example of how to implement

THIS IS JUST A PROTOTYPE /POC

@hutchgrant hutchgrant changed the title WIP: WIP: Server API Feb 3, 2021
@hutchgrant hutchgrant changed the base branch from master to release/0.10.0 February 3, 2021 01:51
@hutchgrant hutchgrant force-pushed the enhancement/issue-470-server-api branch from e3d7af2 to 99dc9cc Compare February 3, 2021 02:03
@hutchgrant hutchgrant closed this Feb 3, 2021
@hutchgrant hutchgrant force-pushed the enhancement/issue-470-server-api branch from 99dc9cc to abd8ee4 Compare February 3, 2021 02:12
@hutchgrant hutchgrant reopened this Feb 3, 2021
@thescientist13 thescientist13 added CLI enhancement Improve something existing (e.g. no docs, new APIs, etc) labels Feb 3, 2021
@thescientist13 thescientist13 added the documentation Greenwood specific docs label Feb 3, 2021
Copy link
Member

@thescientist13 thescientist13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this is definitely a great start and is pretty much mostly complete from what i can see! (aside from needing some docs and considering the below feedback 👇 )

One thought here is that if we can extract the livereload <script> tag snippet out of our standard HTML plugin, we could completely encapsulate all the related functionality. 🎉

So the export could be something like this:

class LiveReloadServer extends ServerInterface {
  ...
}

class LiveReloadResource extends ResourceInterface {
  ...
}

module.exports = (options = {}) => {
  return [{
    type: 'server',
    name: 'plugin-live-reload-server',
    provider: (compilation) => new LiveReloadServer(compilation, options)
  }, { 
    type: 'resource',
    name: 'plugin-live-reload-resource',
    provider: (compilation) => new LiveReloadResource(compilation, options)
  }]
};

And greenwood.config.js would look something like this.

const pluginLiveReload = require('./packages/cli/src/plugins/server/plugin-livereload');

module.exports = {
  plugins: [
    ...pluginLiveReload({ /* options */ }) // notice the spread! ...
  ]
};

I'm sure it could get more elegant with some extra thought, but this definitely gets the job done for now and is pretty effective, IMO.

What I really like about being able to combine it all into one is that later on, I would like to introduce a HotModuleReplacement (HMR) plugin, and thus allow user's the option to choose which developer experience they would like, would be 👌


On a related note about extracting LiveReload from the CLI down the road, is that we will likely want to deprecate devServer from greenwood.config.js since likely each server plugin will have its own unique configuration needs. I think this is good though, since it cleanly moves things out of core and into plugins, which is quite nice. 😃

@thescientist13 thescientist13 added the help wanted Extra attention is needed label Feb 6, 2021
@thescientist13 thescientist13 added the Plugins Greenwood Plugins label Feb 6, 2021
@thescientist13 thescientist13 self-assigned this Feb 15, 2021
@thescientist13 thescientist13 changed the title WIP: Server API Server API Feb 15, 2021
Copy link
Member

@thescientist13 thescientist13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some docs and refactored to make plugin-livereload a Greenwood default server plugin (for now at least).

I will rebase this branch against the release/0.10.0 branch, but will let my changes stand until we can review during this week's meeting, at which point I think then this will be good to merge, barring any major objections.

@thescientist13 thescientist13 removed the help wanted Extra attention is needed label Feb 15, 2021
@thescientist13 thescientist13 changed the title Server API Server Plugin API Feb 15, 2021
@thescientist13 thescientist13 merged commit 1dbe0a6 into release/0.10.0 Feb 18, 2021
@thescientist13 thescientist13 deleted the enhancement/issue-470-server-api branch February 18, 2021 02:39
@thescientist13 thescientist13 mentioned this pull request Feb 18, 2021
12 tasks
@thescientist13 thescientist13 mentioned this pull request Apr 3, 2021
53 tasks
thescientist13 added a commit that referenced this pull request Apr 3, 2021
* task: adding initial server api

* fix lint and cases

* refactor live reload to be internal plugin

* server plugin docs

* updates post ResourceInterface changes from release branch

Co-authored-by: Owen Buckley <owenbuckley13@gmail.com>
thescientist13 added a commit that referenced this pull request Apr 3, 2021
* task: adding initial server api

* fix lint and cases

* refactor live reload to be internal plugin

* server plugin docs

* updates post ResourceInterface changes from release branch

Co-authored-by: Owen Buckley <owenbuckley13@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI documentation Greenwood specific docs enhancement Improve something existing (e.g. no docs, new APIs, etc) Plugins Greenwood Plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

extend a server api so that developers can call custom server plugins
2 participants