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

demo/home page with prototype of HTML / CSS modules (separation of technologies) #13

Conversation

thescientist13
Copy link
Member

@thescientist13 thescientist13 commented Jan 21, 2024

Overview

Trying to play around with a naive attempt at HTML Modules + Constructable Stylesheets (separation of technologies workflow). In its final form I'm sure HTML Modules will return a document.createElement('fragment') or something, but for now just testing new import assertions for the sake of import assertions
Screenshot 2024-01-21 at 6 22 15 PM

:host {
  text-align: center;
  margin-bottom: 40px;
}

:host h2 {
  font-size: 3em;
}

:host h2 i {
  color: var(--color-accent);
}

/* ... */
// hero.html
<div class="hero">
  <h2>The full-stack web is <u><i>here</i></u></h2>
  <p>Greenwood is your workbench for the web, embracing web standards from the ground up to empower your stack from front to back, allowing you to run anywhere the web can run.</p>
  <br/>
  <a href="#">
    <button>Get Started</button>
  </a>
  <a href="#">
    <button>View in Stackblitz</button>
  </a>
  <br/>
  <div class="code">
    $ npx @greenwood/init
  </div>
</div>
// CSS Modules would also be really nice here!
// might work better here for pure static content instead of needing a <style> tag
// note: we don't need a plugin for this in the browser (but likely will need to adapt this for NodeJS / bundling)
import css from './hero.css' with { type: "css" };
import html from "./hero.html" with { type: "html" };

export default class HeroBanner extends HTMLElement {
  connectedCallback() {
    if(!this.shadowRoot) {
     // TODO would be cool explore DOM Parts as a way to do templating with `<template>`s
      const template = document.createElement('template');
      template.innerHTML = html;

      this.attachShadow({ mode: 'open' });
      this.shadowRoot.appendChild(template.content.cloneNode(true));
      this.shadowRoot.adoptedStyleSheets = [css];
    }
  }
}

customElements.define('app-hero', HeroBanner)

This will currently break when running the build task because the version of Rollup / Acorn we're using needs to be upgrade

    SyntaxError [Error]: Unexpected token (2:31)
        at pp$4.raise (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/acorn/dist/acorn.mjs:3554:13)
        at pp$9.unexpected (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/acorn/dist/acorn.mjs:762:8)
        at pp$9.semicolon (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/acorn/dist/acorn.mjs:739:66)
        at pp$8.parseImport (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/acorn/dist/acorn.mjs:1837:8)
        at pp$8.parseStatement (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/acorn/dist/acorn.mjs:938:49)
        at pp$8.parseTopLevel (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/acorn/dist/acorn.mjs:819:21)
        at Parser.parse (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/acorn/dist/acorn.mjs:591:15)
        at Function.parse (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/acorn/dist/acorn.mjs:641:35)
        at Module.parse (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/acorn/dist/acorn.mjs:5943:17)
        at registerDependencies (file:///Users/owenbuckley/Workspace/project-evergreen/www.greenwoodjs.dev/node_modules/wc-compiler/src/wcc.js:69:22) {
      pos: 76,
      loc: { line: 2, column: 31 },
      raisedAt: 80
    }
  

Upstreams

  1. I think this is point we have to do import attributes, as there is basically no way to use a query param in NodeJS custom loaders so this will never work in an isomorphic fashion, e.g. requiring the ?type=html, and so the enforcement of this in Greenwood is inconsistent and non-isomorphic. Basically, the "surest" stack way is actually without the ?type=xxx but obviously that's not as explicit. This would require:
  2. We should also consider a less aggresive stance on NodeJS version in the CLI's package.json
    npm WARN EBADENGINE Unsupported engine {
    npm WARN EBADENGINE   package: '[email protected]',
    npm WARN EBADENGINE   required: { node: '^18.12.1' },
    npm WARN EBADENGINE   current: { node: 'v21.0.0', npm: '10.2.0' }
    npm WARN EBADENGINE }
  3. prerender support in development would be nice here - Rendering Strategies (prerender vs SSR vs CSR) greenwood#951

@thescientist13 thescientist13 added needs upstream Notes that this item exposes an issue with a dependency (usually Greenwood) demo labels Jan 21, 2024
@thescientist13 thescientist13 self-assigned this Jan 21, 2024
@thescientist13 thescientist13 changed the title demo/home page with prototype of HTML modules demo/home page with prototype of HTML modules (separation of technologies) Jan 21, 2024
@thescientist13 thescientist13 mentioned this pull request Jan 21, 2024
18 tasks
@thescientist13 thescientist13 changed the title demo/home page with prototype of HTML modules (separation of technologies) demo/home page with prototype of HTML / CSS modules (separation of technologies) Jan 21, 2024
Copy link

netlify bot commented Feb 21, 2024

Deploy Preview for super-tapioca-5987ce failed.

Name Link
🔨 Latest commit ca8fb61
🔍 Latest deploy log https://app.netlify.com/sites/super-tapioca-5987ce/deploys/65d63f601a507400088a9ec3

@thescientist13
Copy link
Member Author

closing as we've landed on our #7 and I have a personal repo for demo-ing this instead
https://github.com/thescientist13/greenwood-full-stack-web-modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
demo needs upstream Notes that this item exposes an issue with a dependency (usually Greenwood)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant