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

Angular 18自定义输出路径执行ng build --watch时移除browser文件夹

解决Angular 18新构建器watch模式下自定义输出路径生成browser文件夹的问题

以下是无需修改angular.json中development配置的两种可行方案:

  • 方案一:命令行显式指定browser输出路径为空
    在执行watch构建时,除了指定自定义输出路径,额外添加--output-path.browser=""参数,强制让browser产物直接输出到目标路径,而不生成子文件夹:

    ng build --watch --output-path="./自定义路径" --output-path.browser=""
    

    示例:执行ng build --watch --output-path="./my-project-build" --output-path.browser=""后,构建产物会直接生成在my-project-build目录下,不会出现多余的browser子文件夹。

  • 方案二:通过npm脚本简化重复执行
    如果需要频繁使用自定义路径的watch构建,可以在package.json的scripts中添加一个快捷脚本:

    "scripts": {
      "build:watch:custom": "ng build --watch --output-path=\"$CUSTOM_OUTPUT_PATH\" --output-path.browser=\"\""
    }
    

    使用时只需设置环境变量并执行脚本:

    # Linux/macOS
    CUSTOM_OUTPUT_PATH="./my-custom-dist" npm run build:watch:custom
    
    # Windows(PowerShell)
    $env:CUSTOM_OUTPUT_PATH="./my-custom-dist"; npm run build:watch:custom
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 09:12:07