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 是一个纯功能性软件包管理系统,可为每个依赖项分配唯一标识符,这最终意味着您的环境可以无缝包含同一依赖项的多个版本。它还具备可重复性和声明性特征。在 Firebase Studio 上下文中,这意味着您可以在工作区之间共享 Nix 配置文件,以加载相同的环境配置。详细了解 Nix + Firebase Studio。
创建或修改 .idx/dev.nix
文件
环境配置在代码库的 .idx/dev.nix
文件中定义。此文件指定要添加到工作区中的所有组件,包括:
如需查看在 Firebase Studio 中启用应用预览的基本工作区环境配置,请参阅以下示例 .idx/dev.nix
文件:
{ 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
配置文件中的错误并重新构建环境。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-22。
[null,null,["最后更新时间 (UTC):2025-08-22。"],[],[],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\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)."]]