檢視原始碼 mix phx.new (Phoenix v1.7.14)
建立新的 Phoenix 專案。
它預期專案路徑作為引數。
$ mix phx.new PATH [--module MODULE] [--app APP]
一個專案會在指定的 PATH 建立。應用程式名稱和模組名稱會從路徑取得,除非給定 --module
或 --app
。
選項
--umbrella
- 產生一個 umbrella 專案,有一個應用程式給你的網域,還有一個應用程式給 web 介面。--app
- OTP 應用程式的名稱--module
- 產生的結構中的基本模組名稱--database
- 指定 Ecto 的資料庫介面。下列之一postgres
- 透過 https://github.com/elixir-ecto/postgrexmysql
- 透過 https://github.com/elixir-ecto/myxqlmssql
- 透過 https://github.com/livehelpnow/tdssqlite3
- 透過 https://github.com/elixir-sqlite/ecto_sqlite3
請查看驅動程式文件以取得更多資訊和需求。預設為「postgres」。
--adapter
- 指定 http 介面。下列之一cowboy
- 透過 https://github.com/elixir-plug/plug_cowboybandit
- 透過 https://github.com/mtrudel/bandit
請查看介面文件以取得更多資訊和需求。預設為「bandit」。
--no-assets
- 等於--no-esbuild
和--no-tailwind
--no-dashboard
- 不包含 Phoenix.LiveDashboard--no-ecto
- 不要產生 Ecto 檔案--no-esbuild
- 不要包含 esbuild 相依性和素材。我們不建議設定此選項,除非僅限 API 應用程式,因為這樣會強制你手動新增和追蹤 JavaScript 相依性--no-gettext
- 不要產生 gettext 檔案--no-html
- 不要產生 HTML 檢視--no-live
- 在端點和 assets/js/app.js 中註解掉 LiveView socket 設定。如果給定 --no-html,會自動停用--no-mailer
- 不要產生 Swoosh mailer 檔案--no-tailwind
- 不包含 tailwind 相依性及其資產。所產生的標記仍將包含 Tailwind CSS 類別,它們保留為您稍後進行版面配置和元件樣式的參考--binary-id
- 使用binary_id
作為 Ecto schema 中的基礎金鑰類型--verbose
- 使用詳細輸出-v
,--version
- 列印 Phoenix 安裝程式的版本
傳遞 --no-ecto
標記時,例如 phx.gen.html
、phx.gen.json
、phx.gen.live
和 phx.gen.context
等 Phoenix 產生器可能無法按預期運作,因為它們會產生依賴 Ecto 以存取資料庫的內容檔案。在這種情況下,您可以傳遞 --no-context
標記,產生大部分的 HTML 和 JSON 檔案,但略過內容,讓您可以按需要填入空格。
同樣的,如果給予 --no-html
,phx.gen.html
產生的檔案將無法運作,因為缺少重要的 HTML 元件。
安裝
mix phx.new
預設會提示您提取並安裝您的相依性。您可以傳遞 --install
標記啟用此行為,或使用 --no-install
標記停用。
範例
$ mix phx.new hello_world
等同於
$ mix phx.new hello_world --module HelloWorld
或是不含 HTML 和 JS 的位元(對 API 有用)
$ mix phx.new ~/Workspace/hello_world --no-html --no-assets
作為叢集
$ mix phx.new hello --umbrella
會產生以下目錄結構和模組
hello_umbrella/ Hello.Umbrella
apps/
hello/ Hello
hello_web/ HelloWeb
您可以在使用官方 Elixir 指南 來進一步了解叢集專案