如何通过在单独的文件夹中构建 JS 文件并查看文件来 运行 Angular 4 应用程序?

How to run the Angular 4 Application by building the JS files in a separate folder and watching the files?

我正在尝试学习 Angular 4。在参考 angular 教程时,我能够 运行 该应用程序,但是当 运行 宁 "npm start",系统会在同一个 src 文件夹中创建构建文件。在这里,我试图获取在名为 build 的单独文件夹中创建的 JS 文件,例如 "src/app/build" 和 运行 就在那里。有人可以帮忙解决这个问题吗? 提前致谢。 https://angular.io/tutorial/toh-pt6

使用 AngularCLI 启动一个 Angular 项目并使用 ng serve 它简化了一切!

这是你的 IDE 制造的混乱,因为它是自动将 .ts 传送到 .js。你必须禁用它。

如果您使用 JetBrains IDE,您必须确保 Enable TypeScript compilerPreferences > Languages & Frameworks > TypeScript 中被禁用。

如果是Atom,您需要在tsconfig.json

中设置compileOnSave: false

VScode 不会自动转译 .ts 文件,除非你有 watcher/task runner manually setup 自己

但通常我们对任何 angular 项目使用 angular cli

npm install -g @angular/cli
ng new my-proj
cd my-proj
ng serve