關於 Firebase Studio 工作區
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Firebase Studio 提供雲端式協作開發環境,可簡化使用各種架構和程式庫建構應用程式的程序。
設定 Firebase Studio 工作區後,您就能存取及共用功能齊全的彈性開發環境:Firebase Studio 工作區可透過任何裝置存取,並提供整合式工具,簡化您和團隊的開發程序。
建立工作區
Firebase Studio 中的工作區是開發環境,包含開發應用程式所需的一切工具。其中包含程式碼、程式碼編輯器 (附有與專案相關的外掛程式),以及支援應用程式開發的工具鍊。這就像在本地電腦開發環境中建立新專案一樣,但您擁有預先設定的完整電腦和作業系統,專門用於建構應用程式,在雲端瀏覽器中執行,隨時隨地都能存取。
Firebase Studio 工作區經過最佳化,可包含單一程式碼集,因此您可以將不同應用程式的環境和系統層級依附元件彼此隔離。您可以建立多個工作區,搭配不同的應用程式和架構使用。
如要建立新工作區,請按照下列步驟操作:
複製工作區
複製 Firebase Studio 工作區會建立專案副本,其中包含 home/user
目錄中的所有內容。如果您想試用專案,但不想影響原始專案,或是想以現有專案為基礎建立新專案,這項功能就非常實用。
如要複製工作區,請按照下列步驟操作:
- 在 Firebase Studio 首頁,按一下要複製的工作區旁邊的 more_horiz 選單 >「複製」。
輸入新工作區的名稱,然後按一下「複製」。系統會建立新的工作區,並新增至工作區清單。
ß
注意:複製較大的工作區可能需要幾分鐘的時間。如果新的工作區未載入,請等待 5 分鐘,然後重新整理頁面。
(選用) 如果原始工作區已連結 Firebase 專案,建議為新工作區建立獨立的 Firebase 專案。這樣一來,新工作區就不會變更連結至原始工作區的 Firebase 專案。如要建立 Firebase 專案,請按照下列步驟操作:
- 開啟新工作區,要求 Gemini 為您建立 Firebase 專案。
- 更新參照 Firebase 專案的任何檔案,例如
.env
或 .firebaserc
。
Firebase Studio 使用 Nix 為每個工作區定義環境設定。Nix 是純粹的函式套件管理工具,會為每個依附元件指派專屬 ID,這代表您的環境可以順暢地包含相同依附元件的多個版本。此外,這項技術還可重現及聲明。在 Firebase Studio 的脈絡中,這表示您可以在工作區之間共用 Nix 設定檔,載入相同的環境設定。進一步瞭解 Nix +
Firebase Studio。
建立或編輯 .idx/dev.nix
檔案
環境設定定義在程式碼存放區的 .idx/dev.nix
檔案中。這個檔案會指定要新增至工作區的所有元件,包括:
請參閱下列 .idx/dev.nix
檔案範例,瞭解基本工作區環境設定,以便在 Firebase Studio 中啟用應用程式預覽功能:
{ pkgs, ... }: {
# Which nixpkgs channel to use.
channel = "stable-23.11"; # or "unstable"
# Use https://search.nixos.org/packages to find packages
packages = [
pkgs.nodejs_20
];
# Sets environment variables in the workspace
env = {
SOME_ENV_VAR = "hello";
};
# Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
idx.extensions = [
"angular.ng-template"
];
# Enable previews and customize configuration
idx.previews = {
enable = true;
previews = {
web = {
command = [
"npm"
"run"
"start"
"--"
"--port"
"$PORT"
"--host"
"0.0.0.0"
"--disable-host-check"
];
manager = "web";
# Optionally, specify a directory that contains your web app
# cwd = "app/client";
};
};
};
}
套用新設定
每當您新增或更新 dev.nix
設定檔時,Firebase Studio 都會在右下角顯示「重新建構環境」提示。重建環境所需的時間取決於設定所需的套件數量。
排解環境建構失敗的問題
由於設定檔是可供機器讀取的程式碼,因此可能含有錯誤。如果發生這種情況,環境可能無法建構及啟動。
Firebase Studio 會顯示啟動「復原」環境的選項。
這個工作區不包含您定義的任何設定,只會執行基本 Code OSS。您可藉此修正 dev.nix
設定檔中的錯誤,並重建環境。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-08 (世界標準時間)。
[null,null,["上次更新時間:2025-08-08 (世界標準時間)。"],[],[],null,["Firebase Studio provides a collaborative, cloud-based development\nenvironment that simplifies the process of building applications with an\nextensive combination of\n[frameworks and libraries](https://studio.firebase.google.com/templates).\n\nAfter you set up a Firebase Studio workspace, you can access and share a\nfully-functional, flexible development environment:\nFirebase Studio workspaces are accessible from any device and provide\nintegrated tools to streamline you and your team's development process.\n\nCreate a workspace\n\nA workspace in Firebase Studio is a development environment that\ncontains everything you need to develop your application. It contains your\ncode, a code editor (with plugins relevant to your project), and toolchains\nthat support app development. It's just like creating a new project in your\nlocal desktop development environment, except you have an entire computer\nand operating system pre-configured and dedicated *exclusively* to building\nyour application, running on your browser in the cloud, accessible wherever\nyou are.\n\nFirebase Studio workspaces are optimized to contain a single codebase,\nso you can keep the environments and system-level dependencies of different\napplications isolated from each other. You can create multiple workspaces to\nuse with different applications and frameworks.\n| **Key Point:** There's a limit to the number of workspaces you can create. If you have a [Google Developer Profile](https://developers.google.com/profile/help/overview), you can create more workspaces. Learn more at [Firebase Studio pricing, quotas and limits](/docs/studio/pricing).\n\nTo create a new workspace:\n\n- [Opening a template or sample app](/docs/studio/get-started-template).\n- [Importing a project](/docs/studio/get-started-import).\n- [Prototype with AI](/docs/studio/get-started-ai), then switch to Code view (**`\u003c/\u003e`**).\n\nDuplicate a workspace\n\nDuplicating a Firebase Studio workspace creates a copy of your project that\ncontains everything within the `home/user` directory. This is useful when you\nwant to experiment with a project without affecting the original, or when you\nwant to use an existing project as a starting point for a new one.\n\nTo duplicate a workspace:\n\n1. From the [Firebase Studio homepage](https://studio.firebase.google.com/), click the more_horiz menu next to the workspace you want to copy \\\u003e **Duplicate**.\n2. Enter the name of your new workspace and click **Duplicate**. The new\n workspace is created and added to your list of workspaces.\n ß\n Note: Duplicating larger workspaces can take several minutes. If your new\n workspace doesn't load, wait 5 minutes, then refresh the page.\n\n3. *(Optional)* If the original workspace has a linked Firebase project,\n consider creating a separate Firebase project for your new workspace. This\n prevents your new workspace from making changes to the Firebase project\n linked to your original workspace. To create a Firebase project:\n\n 1. Open the new workspace and ask Gemini to create a Firebase project for you.\n 2. Update any files that reference the Firebase project, such as `.env` or `.firebaserc`.\n\nConfigure your workspace\n\nFirebase Studio uses\n[Nix](https://nixos.org/manual/nix/stable/introduction)\nto define the environment configuration for each workspace. Nix is a purely\nfunctional package manager and assigns unique identifiers to each\ndependency, which ultimately means your environment can contain multiple\nversions of the same dependency, seamlessly. It is also reproducible and\ndeclarative. In the context of Firebase Studio, this means you can\nshare your Nix configuration file across workspaces to load the same\nenvironment configuration. Learn more about [Nix +\nFirebase Studio](/docs/studio/customize-workspace#nix+fs).\n\nCreate or edit the `.idx/dev.nix` file\n\nEnvironment configuration is defined in the `.idx/dev.nix` file in your code\nrepository. This file specifies all of the components to be added to your\nworkspace including:\n\n- [System tools](/docs/studio/customize-workspace#system-tools)\n available from the\n [Nix package registry](https://search.nixos.org/packages),\n including compilers, packages (like `go` or `angular`), and command line\n utilities, like extra\n [gcloud CLI components](/docs/studio/customize-workspace#gcloud).\n\n- [IDE extensions](/docs/studio/customize-workspace#extensions) from the\n [OpenVSX registry](https://open-vsx.org/), like\n language-specific debuggers, code formatters, official extensions for cloud\n services, and more.\n\n- [Common services](/docs/studio/customize-workspace#common-services), like\n docker, Pub/Sub messaging, databases like Postgres and Redis, and\n [more](/docs/studio/devnix-reference).\n\nSee the following example `.idx/dev.nix` file for a basic workspace environment\nconfiguration that enables app previews in Firebase Studio: \n\n { pkgs, ... }: {\n\n # Which nixpkgs channel to use.\n channel = \"stable-23.11\"; # or \"unstable\"\n\n # Use https://search.nixos.org/packages to find packages\n packages = [\n pkgs.nodejs_20\n ];\n\n # Sets environment variables in the workspace\n env = {\n SOME_ENV_VAR = \"hello\";\n };\n\n # Search for the extensions you want on https://open-vsx.org/ and use \"publisher.id\"\n idx.extensions = [\n \"angular.ng-template\"\n ];\n\n # Enable previews and customize configuration\n idx.previews = {\n enable = true;\n previews = {\n web = {\n command = [\n \"npm\"\n \"run\"\n \"start\"\n \"--\"\n \"--port\"\n \"$PORT\"\n \"--host\"\n \"0.0.0.0\"\n \"--disable-host-check\"\n ];\n manager = \"web\";\n # Optionally, specify a directory that contains your web app\n # cwd = \"app/client\";\n };\n };\n };\n }\n\nApply new configuration\n\nAny time you add or update the `dev.nix` configuration file, Firebase Studio\nshows a prompt in the bottom-right corner to **Rebuild the environment**.\nThe time it takes to rebuild the environment depends on the number of packages\nyour configuration needs.\n\nDebug environment build failures\n\nBecause configuration files are machine-readable code, they can have\nerrors. If this happens, the environment may fail to build and not start.\nFirebase Studio displays an option to start a *Recovery* environment.\nThis workspace doesn't include any of the configuration you've defined and\njust runs basic\nCode OSS. This gives you the chance to fix errors in your\n`dev.nix` configuration file and rebuild the environment.\n\nNext steps\n\n- [Customize your\n Firebase Studio workspace](/docs/studio/customize-workspace).\n\n- [Create custom templates to use and share](/docs/studio/custom-templates).\n\n- [Share your workspace](/docs/studio/share-your-workspace).\n\n- [Use an \"Open in Firebase Studio\" button to share your workspace\n configuration or custom template](/docs/studio/open-in-firebase-studio)."]]