You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular6中如何使用ng serve启动自定义本地环境?

How to Launch Custom Local Environment in Angular 6+

Got it, let's get this sorted for you! The --env flag you relied on pre-Angular 6 was replaced with the --configuration (or shorthand -c) option once Angular moved to the angular.json config structure. Here's exactly what you need to do:

1. Use the Updated Serve Command

Instead of the old ng serve --env=local, run this command to activate your custom local configuration:

ng serve --configuration=local

Or use the shorter, more convenient version:

ng serve -c local

This tells the Angular CLI to apply the local configuration you added to angular.json, which will automatically swap your default environment.ts with environment.local.ts as you set up.

2. Verify Your angular.json Configuration

Quick check: make sure your configuration block is properly closed (your snippet was missing a couple of closing braces). It should look like this to avoid CLI errors:

"configurations": {
  "local": {
    "fileReplacements": [
      {
        "replace": "src/environments/environment.ts",
        "with": "src/environments/environment.local.ts"
      }
    ]
  }
}

3. Optional: Add a Convenience Script

If you'll use this local environment frequently, add a shortcut to your package.json scripts section:

"scripts": {
  "start": "ng serve",
  "start:local": "ng serve -c local"
}

Now you can launch your local environment with a simpler command:

npm run start:local

That's all! This will get your custom local environment running just like you had before, but aligned with Angular 6+ CLI standards.

内容的提问来源于stack exchange,提问作者Tampa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:37:09