imba static site
1.0.0
注意:建議新專案使用較新的 https://github.com/imba/imba-vite-template。這個儲存庫將作為 ESBuild 捆綁程式的替代方案保留下來,但隨著我們專注於 Vite 的發展,可能不會看到太多更新。
這是建立靜態託管 Imba 的起點。它還可用於使用 imbutter 將 Imba 建置到本機應用程式中。
原始的build.js腳本在這裡:https://gist.github.com/trafnar/05ebbf0f5193e69f998f41b154d18190
在專案目錄中,您可以運行:
npm start在開發模式下運行應用程式。在瀏覽器中開啟http://localhost:3000即可查看。
如果您進行編輯,頁面將重新載入。您還將在控制台中看到任何 lint 錯誤。
npm run build將用於生產的應用程式建置到dist資料夾中。
請注意, dist/html是靜態版本。
建立一個新的 github 儲存庫並將YOUR_NEW_GITHUB_REPO_URL替換為新儲存庫的 url。
npx imba create project_name
cd project_name
git add --all
git commit -m "initial commit"
git remote add origin YOUR_NEW_GITHUB_REPO_URL
git push -u origin main
npx imba build --baseurl . server.imba
npx touch dist/public/.nojekyll
npx gh-pages --no-history --dotfiles --dist dist/public
若要尋找專案已部署到的 URL,請導覽至儲存庫設定的Pages 。
對於靜態託管,我們使用.作為基本網址。
npx imba build --baseurl . server.imba
是的,即使我們不會使用任何伺服器端文件,我們仍然使用server.imba文件進行建置。
由於 Github Pages 預設使用 Jekyll,因此以下劃線開頭的路徑(如__assets__ )將無法加載,因此我們必須透過執行以下操作來指定我們不想使用 Jekyll:
npx touch dist/public/.nojekyll
一旦所有這些都解決了,使用npx gh-pages實際部署到 github 頁面非常容易,它將建立一個名為gh-pages新 git 分支,並預設從那裡提供我們的檔案。
--dotfiles非常重要,因為需要.nojekyll檔案。dist/public作為基本目錄。gh-pages分支來進行實際版本控制,因此我更喜歡使用--no-history標誌。 npx gh-pages --no-history --dotfiles --dist dist/public