Angular6中如何使用ng serve启动自定义本地环境?
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

