如何在不重新编译的情况下启动Angular应用程序?

时间:2019-12-27 20:48:47

标签: angular

我的第一个Angular应用程序是通过在命令行中键入ng serve(然后按Ent)来构建和运行的,结果是:

10% building 3/3 modules 0 activei 「wds」: Project is running at http://localhost:4200/webpack-dev-server/
i 「wds」: webpack output is served from /
i 「wds」: 404s will fallback to //index.html

chunk {main} main.js, main.js.map (main) 47.9 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 264 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 9.73 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 3.81 MB [initial] [rendered]
Date: 2019-12-27T20:06:20.126Z - Hash: a1e99981ccb691148536 - Time: 5534ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
i 「wdm」: Compiled successfully.

我的问题是:每次提供该应用程序时,都必须重新编译该应用程序吗?

1 个答案:

答案 0 :(得分:1)

TypeScript不是Web浏览器支持的标准语言,要运行TypeScript代码,首先需要将其编译为JavaScript。

此外,Angular在HTML中提供了额外的语法,该语法也不是标准HTML,因此需要将其编译为标准HTML。

由于这个原因,角度应用程序的任何更改都会导致重新编译。您可能想以角度阅读JIT编译。

ng build 之后

在ng构建之后,将生成静态文件,您可以根据需要使用此静态文件。您可以将它们托管在ngix,apache服务器或spring boot项目中。

生成静态文件后,无需进行任何依赖项迁移,因为所需的一切已捆绑在静态文件中。