【问题标题】:How do I build with watch enabled using angular-cli?如何在使用 angular-cli 启用手表的情况下进行构建?
【发布时间】:2017-03-06 14:18:24
【问题描述】:

我不想使用 serve,我知道它会监视更改、构建和服务。 我想在变化的基础上再接再厉。 根据“ng help”,build 需要参数--watch

ng build 构建您的应用并将其放入输出 路径(默认情况下是 dist/)。 --watch(布尔值)(默认值:false) 别名:-w --watcher(字符串)

我尝试了 -w 和 --watcher 但它只是给出了错误。

>ng build -w

Path must be a string. Received null

【问题讨论】:

    标签: angular webpack angular-cli


    【解决方案1】:

    我不知道这是一个错误还是没有记录,但您似乎需要添加一个输出路径以使用 ng build -o dist -w 观看,而 dist 是您的输出路径。

    更新:

    现在的命令是:ng build -op dist -w

    更新 2:

    现在的命令是:ng build --output-path dist --watch

    【讨论】:

    • 对,这是一个已知问题:github.com/DavideViolante/Angular2-Full-Stack/issues/15 所以这解决了问题:ng build -o dist -w
    • 感谢您的链接。我用你的代码 sn-p 更新了我的答案。
    • @StefanNegele Angular 现在在angular.json 中也有输出路径配置,命名为outputPath,在options 变量下。
    【解决方案2】:

    ng build --watch 刚刚为我工作

    如果您使用的是npm run build,请将package.json 文件更新为

    "scripts":{"build":"ng build --watch"}

    像往常一样运行npm run build

    确保您的应用程序的 outDir 参数在您的 angular-cli.json

    中正确设置

    【讨论】:

    • 正是我需要的!谢谢
    • 如何确保每次构建运行时都不会从 outDir 中删除所有文件。
    【解决方案3】:

    ng build --watch 查找路径:dist 以观察变化。但根据新版本的 Angular,默认输出路径为dist/<project-name>

    所以你需要通过命令行提及输出目录

    ng build --output-path dist --watch
    

    您可以将angular.json... -> options -> outputPath: dist/<project-name> 中的默认位置更改为dist,然后运行ng build --watch

    【讨论】:

      【解决方案4】:

      构建和监视 AngularJs 的命令:ng build --poll=2000 --watch

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-10-01
        • 1970-01-01
        • 2018-03-11
        • 2018-12-13
        • 2021-06-18
        • 1970-01-01
        • 1970-01-01
        • 2017-11-29
        相关资源
        最近更新 更多