# WebC is for Single File Web Components ## Features * Framework-independent standalone HTML serializer for generating markup for Web Components. * Expand any HTML element (including custom elements and web components) to HTML with defined conventions from web standards. * This means that Web Components created with WebC are compatible with server-side rendering (without duplicating author-written markup). * Compilation tools to aggregate component-level assets (CSS or JS) for critical CSS or client JavaScript. * Opt-in to scope your component CSS using WebC’s built-in CSS prefixer. * Or, use browser-native Shadow DOM style scoping (for future-compatibility when Declarative Shadow DOM browser support is ubiquitous) * Progressive-enhancement friendly. * Streaming friendly. * Shadow DOM friendly. * Async friendly. ### Integrations/Plugins * [`@11ty/eleventy-plugin-webc`](https://www.11ty.dev/docs/languages/webc/) adds WebC to [Eleventy](https://www.11ty.dev/) * [`express-webc`](https://github.com/NickColley/express-webc) by [@NickColley](https://github.com/NickColley/) adds WebC to [Express](https://expressjs.com/) * [`koa-webc`](https://github.com/sombriks/koa-webc) by [@sombriks](https://github.com/sombriks) adds WebC to [Koa](https://koajs.com/) ### Testimonials > “javascript frameworks are dead to me”—[Andy Bell](https://twitter.com/hankchizljaw/status/1568301299623411715) > “The DX and authoring model you landed on here looks fantastic”—[Addy Osmani](https://twitter.com/addyosmani/status/1568741911690899457) > “Really like the programmatic API approach over using a bundler to pre-compile and then serve.”—[Harminder Virk](https://twitter.com/AmanVirk1/status/1568312188292546566) ### Similar Works Folks doing similar things with Web Components: check them out! * [Enhance](https://enhance.dev/docs/) * [wcc](https://github.com/ProjectEvergreen/wcc) * [Lit SSR](https://lit.dev/docs/ssr/overview/) with plugins for [Eleventy](https://github.com/lit/lit/tree/main/packages/labs/eleventy-plugin-lit#lit-labseleventy-plugin-lit), [Astro](https://docs.astro.build/en/guides/integrations-guide/lit/), and [Rocket](https://rocket.modern-web.dev/docs/basics/components/) ## Installation Note: if you’re **not** building a plugin or integration for WebC, you can probably skip this section! It’s available on [npm as `@11ty/webc`](https://www.npmjs.com/package/@11ty/webc): ``` npm install @11ty/webc ``` This is an ESM project and as such requires a `"type": "module"` in your `package.json` (or use the `.mjs` file extension). ```js import { WebC } from "@11ty/webc"; ``` You _can_ use this in a CommonJS file via dynamic import: ```js (async function() { const { WebC } = await import("@11ty/webc"); })(); ``` ## Examples ### JavaScript API ```js import { WebC } from "@11ty/webc"; let page = new WebC(); // This enables aggregation of CSS and JS // As of 0.4.0+ this is disabled by default page.setBundlerMode(true); // File page.setInputPath("page.webc"); // Or, a String // page.setContent(`

Hello!

`); let { html, css, js, components } = await page.compile(); // Or, Readable Streams for each let { html, css, js } = await page.stream(); ``` ### It’s HTML If WebC looks familiar, that’s because WebC *is* HTML. These are single file HTML components but don’t require any special element conventions (for example Vue’s single file component uses a top-level `