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

Create a plugin for import JSX plugin (using WCC) #972

Closed
1 of 5 tasks
Tracked by #1034
thescientist13 opened this issue Aug 13, 2022 · 0 comments · Fixed by #1085 or #1129
Closed
1 of 5 tasks
Tracked by #1034

Create a plugin for import JSX plugin (using WCC) #972

thescientist13 opened this issue Aug 13, 2022 · 0 comments · Fixed by #1085 or #1129
Assignees
Labels
alpha.5 documentation Greenwood specific docs feature New feature or request good first issue Good for newcomers Plugins Greenwood Plugins v0.28.0
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Aug 13, 2022

Type of Change

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

Summary

With the newest release of WCC@0.6.0, it now supports using JSX inside custom element definitions, with runtime overhead. It is still very experimental, but would be nice to at least lay the ground work for this now.

Details

It should be pretty easy to implement, you can see an example working here:

import { load } from 'wc-compiler/src/jsx-loader.js';
import { ResourceInterface } from '@greenwood/cli/src/lib/resource-interface.js';
import { pathToFileURL } from 'url';

class JsxResource extends ResourceInterface {
  constructor(compilation, options) {
    super(compilation, options);
    this.extensions = ['.jsx'];
    this.contentType = 'text/javascript';
  }

  async serve(url) {
    return new Promise(async (resolve, reject) => {
      try {
        const result = await load(pathToFileURL(url));

        resolve({
          body: result.source,
          contentType: this.contentType
        });
      } catch (e) {
        reject(e);
      }
    });
  }
}

const greenwoodPluginImportJsx = (options = {}) => {
  return [{
    type: 'resource',
    name: 'plugin-import-jsx:resource',
    provider: (compilation) => new JsxResource(compilation, options)
  }];
};

export {
  greenwoodPluginImportJsx
};

Will also want to bump to latest version of WCC as well.

@thescientist13 thescientist13 added good first issue Good for newcomers documentation Greenwood specific docs Plugins Greenwood Plugins feature New feature or request v0.27.0 labels Aug 13, 2022
@thescientist13 thescientist13 added this to the 1.0 milestone Aug 13, 2022
@thescientist13 thescientist13 changed the title create an import JSX plugin Create an import JSX plugin Aug 13, 2022
@thescientist13 thescientist13 changed the title Create an import JSX plugin Create a plugin for import JSX plugin (using WCC) Aug 13, 2022
@thescientist13 thescientist13 self-assigned this Aug 13, 2022
@thescientist13 thescientist13 mentioned this issue Dec 10, 2022
22 tasks
@thescientist13 thescientist13 moved this from 📋 Backlog to 👀 In review in [Greenwood] Phase 9 - Standards and Conventions Mar 28, 2023
@thescientist13 thescientist13 linked a pull request Mar 29, 2023 that will close this issue
@thescientist13 thescientist13 linked a pull request Aug 2, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alpha.5 documentation Greenwood specific docs feature New feature or request good first issue Good for newcomers Plugins Greenwood Plugins v0.28.0
Projects
No open projects
1 participant