{"id":19566300,"url":"https://github.com/juliendargelos/rollup-plugin-web-components","last_synced_at":"2026-05-12T13:36:44.569Z","repository":{"id":51709634,"uuid":"210467573","full_name":"juliendargelos/rollup-plugin-web-components","owner":"juliendargelos","description":"Import and inject web component styles and templates with rollup","archived":false,"fork":false,"pushed_at":"2021-05-10T15:40:59.000Z","size":13,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-15T06:32:49.755Z","etag":null,"topics":["rollup","rollup-plugin","web-components"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juliendargelos.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-23T23:03:59.000Z","updated_at":"2023-03-07T07:42:47.000Z","dependencies_parsed_at":"2022-08-03T09:00:34.768Z","dependency_job_id":null,"html_url":"https://github.com/juliendargelos/rollup-plugin-web-components","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliendargelos%2Frollup-plugin-web-components","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliendargelos%2Frollup-plugin-web-components/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliendargelos%2Frollup-plugin-web-components/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliendargelos%2Frollup-plugin-web-components/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juliendargelos","download_url":"https://codeload.github.com/juliendargelos/rollup-plugin-web-components/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240831009,"owners_count":19864709,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rollup","rollup-plugin","web-components"],"created_at":"2024-11-11T05:30:55.742Z","updated_at":"2026-05-12T13:36:39.537Z","avatar_url":"https://github.com/juliendargelos.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rollup-plugin-web-components\n\nThis plugin provides a loader for single file web components, and injects their templates into html files.\n\n## Install\n\n```bash\nyarn add rollup-plugin-web-components --dev\n```\n\nor\n\n```bash\nnpm install rollup-plugin-web-components -D\n```\n\n## Usage\n\nThis plugin only injects component templates to assets emitted with the [emitFile()](https://rollupjs.org/guide/en/#thisemitfileemittedfile-emittedchunk--emittedasset--string) plugin context method and having `.html` as extension.\n\nThe following example uses [rollup-plugin-emit-files](https://github.com/juliendargelos/rollup-plugin-emit-files) to emit html pages to rollup bundle.\n\n```javascript\n// rollup.config.js\n\nimport webComponents from 'rollup-plugin-web-components'\nimport emitFiles from 'rollup-plugin-emit-files'\n\nexport default {\n  // ...\n  plugins: [\n    webComponents(),\n    emitFiles({\n        src: 'src/pages',\n        include: '**/*.html'\n    })\n  ]\n}\n```\n\n```html\n\u003c!-- src/components/x-button.html !--\u003e\n\n\u003ctemplate id=\"x-button\"\u003e\n  \u003cspan\u003e\n    \u003cslot\u003e\u003c/slot\u003e\n  \u003c/span\u003e\n\u003c/template\u003e\n\n\u003c!-- The style element can be either inside or outside the template element !--\u003e\n\n\u003cstyle\u003e\n  :host {\n    border: 1px solid black;\n    cursor: pointer;\n  }\n\u003c/style\u003e\n\n\u003cscript\u003e\n  export class XButton extends HTMLElement {\n    constructor() {\n      super()\n\n      const template = document.getElementById('x-button')\n\n      this\n        .attachShadow({ mode: 'open' })\n        .appendChild(template.content.cloneNode(true))\n    }\n  }\n\u003c/script\u003e\n```\n\n```javascript\n// src/index.js\n\nimport {\n    template, // template as string\n    style, // style as string\n    XButton // Anything else exported from the script tag is also available\n} from './components/x-button.html'\n\ncustomElements.define('x-button', XButton)\n```\n\n```html\n\u003c!-- src/pages/index.html !--\u003e\n\n\u003c!doctype html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003ctitle\u003ePage with web components\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cx-button\u003ehey\u003c/x-button\u003e\n    \u003cscript src=\"index.js\"\u003e\u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nThe output folder will contain the following `index.html` file:\n\n```html\n\u003c!doctype html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003ctitle\u003ePage with web components\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ctemplate id=\"x-button\"\u003e\n      \u003cstyle\u003e\n        :host {\n          border: 1px solid black;\n          cursor: pointer;\n        }\n      \u003c/style\u003e\n      \u003cspan\u003e\n        \u003cslot\u003e\u003c/slot\u003e\n      \u003c/span\u003e\n    \u003c/template\u003e\n\n    \u003cx-button\u003ehey\u003c/x-button\u003e\n    \u003cscript src=\"index.js\"\u003e\u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nNo matter wether the style element is inside or outside the template element:\n\n- It will always be **inside** when injected into html\n- It will always be **removed** and **exported separatly** when imported from javascript\n\n## Options\n\n```typescript\n{\n  extension?: string\n  inject?: boolean\n}\n```\n\n### extension\n\nThe extension which must be loaded with the web-components loader.\n\nDefault: `'.html'`\n\n### inject\n\nIf set to true, the plugin will inject all templates from imported components to all html files emitted in the rollup bundle.\n\nDefault: `true`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliendargelos%2Frollup-plugin-web-components","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliendargelos%2Frollup-plugin-web-components","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliendargelos%2Frollup-plugin-web-components/lists"}