斜阳下的凤凰 發表於 2023-2-14 22:22:00

使用 vuepress + gitee-pages + gitee-go 搭建静态网站

<h2 id="准备">准备</h2>
<p>创建 &amp; 运行项目,请参考 VuePress(v1):https://v1.vuepress.vuejs.org/zh/guide/</p>
<h2 id="构建和推送静态网站">构建和推送静态网站</h2>
<p>使用 npm 构建静态网站并将其推送到 Gitee Pages 页面服务托管的分支</p>
<p>方式一:shell 脚本</p>
<pre><code class="language-sh">if [ ! -e package.json ]; then
echo '请在 package.json 所在目录下执行该脚本!'
exit
fi

if [ -d "docs/.vuepress/dist" ]; then
rm -rf docs/.vuepress/dist
fi

echo '🚀 开始构建...'

npm run build # &gt; /dev/null 2&gt;&amp;1

if [ $? -ne 0 ]; then
    echo "❌ 构建失败。请使用 npm run build 命令构建以查看详情"
    exit
fi

echo '🎉 构建成功!'

echo '开始将生成的静态网站推送至 gt-pages 分支'

cd docs/.vuepress/dist &amp;&amp; git init&amp;&amp; git checkout --orphan gt-pages\
&amp;&amp; git add .&amp;&amp; git commit -m "pushed by deploy.sh"\
&amp;&amp; git remote add origin git@gitee.com:engureguo/ops.git\
&amp;&amp; git push origin gt-pages --force&amp;&amp; rm -rf .git
## git@gitee.com:engureguo/ops.git 为远程仓库
## gt-pages 为静态网站部署分支

if [ $? -ne 0 ]; then
    echo "❌ 抱歉,推送失败了"
    exit
fi

echo '🎉 推送成功!'
</code></pre>
<p>方式二:Gitee Go 流水线</p>
<pre><code class="language-yaml">version: '1.0'
name: pipeline-20230214
displayName: pipeline-20230214
triggers:
trigger: auto
push:
    branches:
      prefix:
      - main
stages:
- name: stage-5caca387
    displayName: 构建和推送
    strategy: naturally
    trigger: auto
    executor: []
    steps:
      - step: build@nodejs
      name: build_nodejs
      displayName: Nodejs 构建
      nodeVersion: 16.14.2
      commands:
          - npm config set registry https://registry.npmmirror.com
          - npm install &amp;&amp; npm run build &amp;&amp; cd docs/.vuepress/dist
          - git init . &amp;&amp; git config --local init.defaultBranch master
          - git config --global user.email "your@email.com"
          - git config --global user.name "GiteeGo Pipeline"
          - git add . &amp;&amp;git commit -m "pushed by gitee-go"
          - git push https://${USERNAME}:${ACCESS_TOKEN}@gitee.com/${GITEE_REPO} master:gt-pages --force
          # 配置有户名和密码:
          # 1.定义全局变量。在【通用变量】中创建 USERNAME 和 ACCESS_TOKEN
          # 2.定义流水线级别变量。编辑流水线 -&gt; 变量设置 -&gt; 引用变量 -&gt; 保存!
      artifacts:
          - name: BUILD_ARTIFACT
            path:
            - ./docs/.vuepress/dist
      caches:
          - ~/.npm
          - ~/.yarn
      notify: []
      strategy:
          retry: '0'
</code></pre>
<p>更多内容,请参考:https://gitee.com/engureguo/ops</p>


</div>
<div id="MySignature" role="contentinfo">
    沉舟侧畔千帆过,病树前头万木春。<br><br>
来源:https://www.cnblogs.com/egu0/p/17121084.html
頁: [1]
查看完整版本: 使用 vuepress + gitee-pages + gitee-go 搭建静态网站