【问题标题】:Is possible build nodejs to static using Github pages online?是否可以在线使用 Github 页面将 nodejs 构建为静态?
【发布时间】:2019-01-06 10:29:07
【问题描述】:

我有两个存储库:

  1. 一个包含 Nodejs 源代码和 markdown 文件的 Vuepress 项目。
  2. 从 Vuepress 构建的静态 Github 页面。

因此,如果我创建一个新的降价帖子,我需要运行 shell 来构建静态文件并将其上传到第二个 Github-pages 存储库。

我想知道是否可以在线执行此操作,例如:

  1. 在 Github 网页中创建 markdown 文件。
  2. 在线重建项目(使用 shell 或脚本?)。
  3. 使用生成的静态 HTML/CSS 文件更新 Github 页面。

【问题讨论】:

标签: node.js github-pages vuepress


【解决方案1】:

我使用这个 .js 代码:

#!/usr/bin/env node
const shell = require("shelljs");
const ghpages = require("gh-pages");

// Variables
const distDirectory = "docs/.vuepress/dist";
const commitMessage = "Site update";

// Exit if there is any error
shell.set("-e");

// Build Vuepress
shell.exec("vuepress build docs");

// Publish to GitHub Pages
ghpages.publish(distDirectory, {
  message: commitMessage
}, function(err) {
  if (err) {
    console.log(err);
    shell.exit(1);
  }
});

// Message when succesfully completed
console.log("\nDocumentation has been successfully updated\n");

记住shelljsgh-pages必须安装。

这是做什么的:

  • 构建 Vuepress
  • dist 从 master 发布到 gh-pages。 .gitignore 可以忽略 dist 文件夹。

现在要使用它,在终端上运行这个命令:

./path/to/file.js

我确信这可以用 shell 完成,但这对我来说非常有效。从理论上讲,只需一个命令,您就可以 lint JS 和 CSS、构建 Vuepress、更新版本、推送到 gh-pages、推送到 master 并发布到 npm。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-20
    • 2021-02-17
    • 2023-01-30
    • 2018-09-10
    • 2014-05-07
    • 2015-12-30
    • 2020-05-28
    • 1970-01-01
    相关资源
    最近更新 更多