當使用 create-remix
產生新專案時,您可以選擇範本或堆疊來快速啟動並運行。範本是讓您快速啟動並運行的最小起點。「堆疊」是更完整、更接近生產就緒架構的範本(可能包括測試、資料庫、CI 和部署配置等方面)。
如果您在執行 create-remix
時未提供 --template
選項,您將獲得一個使用 Remix 應用程式伺服器的基本範本。
npx create-remix@latest
如果您對使用 TypeScript 不感興趣,您可以改為安裝更簡單的 Javascript 範本
npx create-remix@latest --template remix-run/remix/templates/remix-javascript
如果您只是想第一次嘗試 Remix,這是一個很好的起點。您可以隨時自行擴充此起點,或稍後遷移到更進階的範本。
如果您想要更多控制您的伺服器,或希望部署到非 Node 執行階段(例如 Arc、Cloudflare 或 Deno),那麼您可以嘗試我們在 Remix 儲存庫中的 官方範本之一
npx create-remix@latest --template remix-run/remix/templates/cloudflare
npx create-remix@latest --template remix-run/remix/templates/cloudflare-workers
npx create-remix@latest --template remix-run/remix/templates/express
npx create-remix@latest --template remix-run/remix/templates/remix
npx create-remix@latest --template remix-run/remix/templates/remix-javascript
## SPA Mode
npx create-remix@latest --template remix-run/remix/templates/spa
## Classic Remix Compiler
npx create-remix@latest --template remix-run/remix/templates/classic-remix-compiler/arc
npx create-remix@latest --template remix-run/remix/templates/classic-remix-compiler/cloudflare-pages
npx create-remix@latest --template remix-run/remix/templates/classic-remix-compiler/cloudflare-workers
npx create-remix@latest --template remix-run/remix/templates/classic-remix-compiler/deno
npx create-remix@latest --template remix-run/remix/templates/classic-remix-compiler/express
npx create-remix@latest --template remix-run/remix/templates/classic-remix-compiler/fly
npx create-remix@latest --template remix-run/remix/templates/classic-remix-compiler/remix
npx create-remix@latest --template remix-run/remix/templates/classic-remix-compiler/remix-javascript
某些託管服務供應商維護自己的 Remix 範本。如需更多資訊,請參閱下方列出的官方整合指南。
我們還提供了一個社群驅動的範例儲存庫,每個範例都展示了不同的 Remix 功能、模式、工具、託管服務供應商等。您可以使用類似的方式來安裝工作範例
npx create-remix@latest --template remix-run/examples/basic
當範本更接近成為生產就緒的應用程式時,以至於它提供了關於 CI/CD 管道、資料庫和託管平台的觀點時,Remix 社群將這些範本稱為「堆疊」。
提供了幾個官方堆疊,但您也可以製作自己的堆疊(請閱讀下文瞭解更多資訊)。
閱讀功能公告部落格文章和在 YouTube 上觀看 Remix 堆疊影片。
官方堆疊已準備好您生產應用程式所需的常見內容,包括
您所擁有的就是一切都已完全設定好,讓您可以開始使用 Remix 建立任何您想建構的驚人網路體驗。以下是官方的堆疊:
您可以透過在執行 create-remix
時提供 --template
選項來使用這些堆疊,例如:
npx create-remix@latest --template remix-run/blues-stack
是的,它們是以音樂類型命名的。🤘 搖滾吧。
您可以在 GitHub 上瀏覽社群堆疊的清單。
社群堆疊可以透過將 GitHub 使用者名稱/儲存庫組合傳遞給執行 create-remix
時的 --template
選項來使用,例如:
npx create-remix@latest --template :username/:repo
如果您的範本位於私有 GitHub 儲存庫中,您可以透過 --token
選項傳遞 GitHub 權杖
npx create-remix@latest --template your-private/repo --token yourtoken
您可以將本機目錄或磁碟上的 tarball 提供給 --template
選項,例如:
npx create-remix@latest --template /my/remix-stack
npx create-remix@latest --template /my/remix-stack.tar.gz
npx create-remix@latest --template /my/remix-stack.tgz
npx create-remix@latest --template file:///Users/michael/my-remix-stack.tar.gz
如果您在 package.json 中將任何相依性設定為 *
,Remix CLI 會將其變更為已安裝 Remix 版本的 semver caret (插入符號)
- "remix": "*",
+ "remix": "^2.0.0",
這讓您不必定期將範本更新為該特定套件的最新版本。當然,如果您希望手動管理該套件的版本,則不必放置 *
。
如果範本在根目錄下有一個 remix.init/index.js
檔案,則該檔案會在專案產生且相依性已安裝後執行。這讓您可以在範本初始化時執行任何您想要的操作。例如,在藍調堆疊中,app
屬性必須是全域唯一的,因此我們使用 remix.init/index.js
檔案將其變更為為專案建立的目錄名稱 + 幾個隨機字元。
您甚至可以使用 remix.init/index.js
向開發人員詢問更多問題以進行其他設定(使用類似 inquirer 的工具)。有時,您需要安裝相依性才能執行此操作,但這些相依性僅在初始化期間有用。在這種情況下,您也可以建立具有相依性的 remix.init/package.json
,Remix CLI 會在執行您的腳本之前安裝這些相依性。
執行初始化腳本後,remix.init
資料夾會被刪除,因此您不必擔心它會使完成的程式碼庫雜亂。
remix.init
腳本。要手動執行此操作,他們需要執行 remix init
。