New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eleventy-plugin-wcc

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eleventy-plugin-wcc

An Eleventy plugin for rendering Web Components with WCC.

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

eleventy-plugin-wcc

Overview

Eleventy plugin for rendering native Web Components using Web Components Compiler (WCC).

A starter kit for 11ty + WCC is also available.

Installation

Install from NPM.

$ npm install eleventy-plugin-wcc --save-dev

Configuration

Add the plugin to your eleventy.js config and provide a URL for all top level custom element definitions you use.

const path = require('path');
const { pathToFileURL } = require('url');
const wccPlugin = require('./src/index');

module.exports = function(eleventyConfig) {
  eleventyConfig.addPlugin(wccPlugin, {
    definitions: [
      pathToFileURL(path.join(__dirname, './src/js/my-element.js'))
    ]
  });
};

Usage

1. Create a Custom Element

Write a custom element like below. In this case, we are using Declarative Shadow DOM.

// src/js/greeting.js
const template = document.createElement('template');

template.innerHTML = `
  <p>Hello from the greeting component!</p>
`;

class GreetingComponent extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({ mode: 'open' });
  }

  async connectedCallback() {
    this.shadowRoot.appendChild(template.content.cloneNode(true));
  }
}

module.exports = GreetingComponent; // using module.exports!

customElements.define('x-greeting', GreetingComponent);

Note: Since Eleventy does not support ESM yet, you will need to use module.exports = XXX instead of export default XXX for your definitions.

2. Update Configuration

Add your custom element paths to your .eleventy.js config

const path = require('path');
const { pathToFileURL } = require('url');
const wccPlugin = require('eleventy-plugin-wcc');

module.exports = function(eleventyConfig) {
  eleventyConfig.addPlugin(wccPlugin, {
    definitions: [
      pathToFileURL(path.join(__dirname, './src/js/greeting.js'))
    ]
  });
};

3. Use It!

Now in your content or layouts, use the custom element.

<!-- src/index.md -->
# Hello From 11ty + WCC! 👋

<x-greeting></x-greeting>

Now if you run eleventy, you should get an index.html in your site/ directory with the custom element content pre-rendered! 🎈

<h2>Hello From 11ty + WCC!</h2>
<p>
  <x-greeting>
    <template shadowroot="open">
      <p>Hello from the greeting component!</p>
    </template>
  </x-greeting>
</p>

Options

Coming soon!

Please follow along in our issue tracker or make a suggestion!

Keywords

FAQs

Package last updated on 27 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc