Firebase Studio 提供雲端式協作開發環境,可簡化使用各種架構和程式庫建構應用程式的程序。
設定 Firebase Studio 工作空間後,您就能存取及共用功能齊全的彈性開發環境:Firebase Studio 工作空間可透過任何裝置存取,並提供整合式工具,簡化您和團隊的開發程序。
建立工作區
Firebase Studio 中的工作區是開發環境,包含開發應用程式所需的一切工具。其中包含程式碼、程式碼編輯器 (附有與專案相關的外掛程式),以及支援應用程式開發的工具鍊。這就像在本地電腦開發環境中建立新專案一樣,但您擁有預先設定的完整電腦和作業系統,專門用於建構應用程式,在雲端瀏覽器中執行,隨時隨地都能存取。
Firebase Studio 工作區經過最佳化,可包含單一程式碼集,因此您可以將不同應用程式的環境和系統層級依附元件彼此隔離。您可以建立多個工作區,搭配不同的應用程式和架構使用。
請參閱下列 .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 packagespackages=[
pkgs.nodejs_20
];# Sets environment variables in the workspaceenv={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 設定檔中的錯誤,並重建環境。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-06 (世界標準時間)。"],[],[],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)."]]