{"id":20669110,"url":"https://github.com/jackchoumine/stencil-component","last_synced_at":"2025-03-10T16:03:36.137Z","repository":{"id":124185739,"uuid":"443774623","full_name":"jackchoumine/stencil-component","owner":"jackchoumine","description":"学习 stencil componen 记录","archived":false,"fork":false,"pushed_at":"2022-03-27T11:00:42.000Z","size":293,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-17T13:30:32.236Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/jackchoumine.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-02T13:36:08.000Z","updated_at":"2022-01-11T02:16:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"e47e602b-aff2-43f4-856b-bdbadc11a80e","html_url":"https://github.com/jackchoumine/stencil-component","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/jackchoumine%2Fstencil-component","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackchoumine%2Fstencil-component/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackchoumine%2Fstencil-component/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackchoumine%2Fstencil-component/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jackchoumine","download_url":"https://codeload.github.com/jackchoumine/stencil-component/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242883697,"owners_count":20200979,"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":[],"created_at":"2024-11-16T20:13:00.965Z","updated_at":"2025-03-10T16:03:36.100Z","avatar_url":"https://github.com/jackchoumine.png","language":"TypeScript","readme":"# Stencil App Starter\n\nStencil is a compiler for building fast web apps using Web Components.\n\nStencil combines the best concepts of the most popular frontend frameworks into a compile-time rather than run-time tool. Stencil takes TypeScript, JSX, a tiny virtual DOM layer, efficient one-way data binding, an asynchronous rendering pipeline (similar to React Fiber), and lazy-loading out of the box, and generates 100% standards-based Web Components that run in any browser supporting the Custom Elements v1 spec.\n\nStencil components are just Web Components, so they work in any major framework or with no framework at all. In many cases, Stencil can be used as a drop in replacement for traditional frontend frameworks given the capabilities now available in the browser, though using it as such is certainly not required.\n\nStencil also enables a number of key capabilities on top of Web Components, in particular Server Side Rendering (SSR) without the need to run a headless browser, pre-rendering, and objects-as-properties (instead of just strings).\n\n## Getting Started\n\nTo start a new project using Stencil, clone this repo to a new directory:\n\n```bash\nnpm init stencil app\n```\n\nand run:\n\n```bash\nnpm start\n```\n\nTo build the app for production, run:\n\n```bash\nnpm run build\n```\n\nTo run the unit tests once, run:\n\n```\nnpm test\n```\n\nTo run the unit tests and watch for file changes during development, run:\n\n```\nnpm run test.watch\n```\n\n## vue2 如何引入 stencil web component\n\n### 引入组件\n\n两种方式：\n\n1. 通过 cnd 引入 web component\n\nindex.html 中\n\n```html\n\u003cscript type=\"module\" async src=\"https://unpkg.com/stencil-rating-component-test\"\u003e\u003c/script\u003e\n```\n\n从 jsdelivr 引入不行：\n\n```html\n\u003c!-- NOTE 不行 package 需要设置 jsdelivr browser main 没设置好 --\u003e\n\u003cscript\n  type=\"module\"\n  src=\"https://cdn.jsdelivr.net/npm/stencil-rating-component-test@1.0.1/dist/esm/index.js\"\n\u003e\u003c/script\u003e\n```\n\n2. 安装 npm\n\n```bash\nnpm i stencil-rating-component-test\n```\n\n在 main.js\n\n```js\nimport { defineCustomElements } from 'stencil-rating-component-test/loader'\ndefineCustomElements()\n```\n\n### 让 vue 识别 web component 和 vue component, vue 会跳过 web component 编译\n\nmain.js\n\n```js\nVue.config.ignoredElements = [/^([a-z][a-z0-9]*)(-[a-z0-9]+)*$/]\n```\n\nvue.config.js\n\n```js\nmodule.exports = {\n  chainWebpack: config =\u003e {\n    // config.resolve.symlinks(false),\n    config.module\n      .rule('vue')\n      .use('vue-loader')\n      .tap(options =\u003e ({\n        ...(options || {}),\n        compilerOptions: {\n          isCustomElement: tag =\u003e tag.includes('-'),\n        },\n      }))\n  },\n}\n```\n\n为了格式化方便，eslint 的规则配置\n\n```js\n'vue/component-name-in-template-casing': 0,// 不检查组件写法\n// kebab-case 写法的标签是自定义元素\n// PascalCase 风格的是 vue 组件\n```\n\n### 使用\n\n```html\n\u003c!-- NOTE 复杂数据：（对象和数组）、希望动态绑定的数据，添加 prop --\u003e\n\u003cdonut-chart\n  :label-color=\"labelColor\"\n  :label-size=\"labelSize\"\n  :label-weight=\"labelWeight\"\n  :themes=\"chartSettings.themes\"\n  :innerRadius=\"innerRadius\"\n  :chartType.prop=\"chartSettings.chartType\"\n  :data.prop=\"data\"\n  :size.prop=\"previewSize\"\n/\u003e\n```\n\n监听事件和 vue 组件一样。\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackchoumine%2Fstencil-component","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjackchoumine%2Fstencil-component","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackchoumine%2Fstencil-component/lists"}