<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by yiren.goo on Medium]]></title>
        <description><![CDATA[Stories by yiren.goo on Medium]]></description>
        <link>https://medium.com/@yiren.goo?source=rss-93918dbeac51------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*MV-MtTc5PWliOVBZ.jpg</url>
            <title>Stories by yiren.goo on Medium</title>
            <link>https://medium.com/@yiren.goo?source=rss-93918dbeac51------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 05:30:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yiren.goo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Step By Step 部署angular/cli專案至Github Pages]]></title>
            <link>https://medium.com/%E8%83%96%E5%8F%A4%E7%9A%84%E6%97%A5%E5%B8%B8%E7%99%BD%E8%A9%B1%E7%A8%8B%E5%BC%8F/step-by-step-%E9%83%A8%E7%BD%B2angular-cli%E5%B0%88%E6%A1%88%E8%87%B3github-pages-5dea52ba7b5e?source=rss-93918dbeac51------2</link>
            <guid isPermaLink="false">https://medium.com/p/5dea52ba7b5e</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angular-cli]]></category>
            <category><![CDATA[github-pages]]></category>
            <dc:creator><![CDATA[yiren.goo]]></dc:creator>
            <pubDate>Sun, 10 Jun 2018 12:15:55 GMT</pubDate>
            <atom:updated>2018-06-10T12:28:23.011Z</atom:updated>
            <content:encoded><![CDATA[<p>(angular/cli)用ng new一個專案，在local完成開發後，有很多選擇可以把Angular App部署到remote server，免費中最簡單的之一就是<a href="https://pages.github.com/">Github Pages</a>，</p><p>流程上是這樣:</p><ol><li>要有Github帳號(你沒有!?)</li><li>在cli專案目錄下 執行ng build產生部署檔案(詳細指令在下面)</li><li>(Optional, 因為一台電腦設定一次就不用在設定了) 設定SSH Keys，<a href="https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/">官方教學</a>很清楚，一步一步照做就可以了</li><li>安裝 <a href="https://github.com/angular-schule/angular-cli-ghpages">angular-cli-ghpages</a> 套件(npm i -g angular-cli-ghpages)</li><li>在專案目錄下，執行ngh(詳細指令在下面)，dist目錄下的angular app發佈到Github Pages</li><li>打開瀏覽器(<a href="https://{yourname}.github.io/%7Brepository_name%7D/">https://{yourname}.github.io/{repository_name}/</a>)驗收，原則上馬上可以瀏覽，有時候出現404，要等個幾分鐘，。</li></ol><p>我的Angular CLI 版本如下:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QHKSagQDjWAQzQRBqqYWrA.png" /></figure><p>但照上面的步驟，不會有錯誤訊息，直到打開瀏覽器….</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-OCeQ_7gv3x3b82W5sNSqQ.png" /></figure><p>因為預設base href為”/”，會發生相關的js及css檔not found，因為路徑不對，相關的檔案應放在<a href="https://yiren.github.io/ngToDo/">https://{你的github名字}.github.io/{Repository名稱}/</a>下。</p><p>所以部署到Github Pages，base href要設定為 <a href="https://yiren.github.io/ngToDo/">https://{你的github名字}.github.io/{Repository名稱}/</a>，故ng build完整參數應為(以我其中一個專案為例):</p><pre>ng build -- prod -- base-href &quot;<a href="https://yiren.github.io/ngToDo/">https://yiren.github.io/ngToDo/</a>&quot;</pre><p>完成後應開可以看到:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8NUhQBFkhO3_-R31XCpXiw.png" /></figure><p>更重要的是到dist/{專案名稱}/index.html下確認&lt;base href&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*flLhFGR98H29fE8vpil1Lg.png" /></figure><p>另外直接執行ngh，會出現錯誤訊息:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*63nFIu1vwmOnQT59ImU_IA.png" /></figure><p>查官方Github，這是SSH Credential 的問題，官方推薦指令:</p><pre>angular-cli-ghpages --repo=https://GH_TOKEN@github.com/organisation/your-repo.git --name=&quot;Displayed Username&quot; --email=mail@example.org</pre><p>不一定要用https，用SSH也可以，只要指定repo: git@github.co:xxx/yyy.git</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*4IMncGS7sr1SkGYB2GXw_A.png" /></figure><p>另外angular6好像有人遇到小問題</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KNPOm1mynEsDiuV4gVqmsQ.png" /></figure><p>最後綜合以上兩個tips，我可以work的指令如下:</p><pre>ngg --dir dist/ngtodo --<a href="/service/mailto:repo=git@github.com">repo=git@github.com</a>:yiren/ngToDo.git --no-silent</pre><p>no-slient是會印出ngh完整的執行過程以及錯誤訊息(如果有的話)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uEOQ5P3vN8qzJ8f6CnJDHA.png" /></figure><p>看到最後一行，就打開瀏覽器看看吧</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZKc0IfXZ4NCMMioYjXgogw.png" /></figure><p>OK!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5dea52ba7b5e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/%E8%83%96%E5%8F%A4%E7%9A%84%E6%97%A5%E5%B8%B8%E7%99%BD%E8%A9%B1%E7%A8%8B%E5%BC%8F/step-by-step-%E9%83%A8%E7%BD%B2angular-cli%E5%B0%88%E6%A1%88%E8%87%B3github-pages-5dea52ba7b5e">Step By Step 部署angular/cli專案至Github Pages</a> was originally published in <a href="https://medium.com/%E8%83%96%E5%8F%A4%E7%9A%84%E6%97%A5%E5%B8%B8%E7%99%BD%E8%A9%B1%E7%A8%8B%E5%BC%8F">胖古的日常白話程式</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>