如何使用节点模块中的 Web 组件依赖项部署到 GitHub 页面

How to deploy to GitHub pages with Web Components Dependencies in Node Modules

我正在尝试使用 Github 页面托管我的网站。我目前正在使用 Web 组件和 Lit-HTML(无 Lit 元素)。没有服务器端代码。只使用 NPM 和节点模块。我想构建站点并发布到我的 git 分支 gh-pages 但我不太确定我需要采取什么步骤,因为当前页面错误,因为它找不到依赖项。

我目前 运行 在我的 Windows 机器上使用 WAMP 本地站点。在这里完美运行。不确定是否可以编译代码使其成为 Jekyll 格式

编辑:我知道如何将代码推送到 Github。只是不确定 Github 如何使用节点模块来构建站点。

这是我的 Package.json

{
  "name": "Repo",
  "version": "1.0.0",
  "description": "Description",
  "dependencies": {
    "@webcomponents/webcomponentsjs": "^2.2.1",
    "lit-html": "^1.0.0"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/username/Repo.git"
  },
  "author": "ME",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/username/Repo/issues"
  },
  "homepage": "https://homepage.com"
}

这取决于您希望从何处获取依赖项。

您想在自己的网站上托管它们吗?也许没有必要。相反,您可以直接从其原始 CDN 获取它们。

对于 webcomponentsjsaccording to their website,它在 unpkg.com CDN 上。

<script src="https://unpkg.com/@webcomponents/webcomponentsjs@^2/webcomponents-bundle.js"></script>

对于lit-htmlaccording to the doc,它也在unpkg.com CDN上:

import {html, render} from 'https://unpkg.com/lit-html?module'