什么是最好的方法来捆绑Angular(版本2,4,6,......)在一个活的Web服务器上进行生产。
请在答案中包括Angular的版本,这样我们可以在它转到以后的版本时更好地跟踪。
2.x, 4.x, 5.x, 6.x, 7.x, 8.x
(TypeScript)与Angular CLInpm install -g @angular/cli
。ng new projectFolder
创建一个新的应用程序ng build --prod
(当目录为`projectFolder'时在命令行中运行)
*标志着prod
捆绑用于生产(关于生产标志所包含的选项列表,请参见Angular文档)。
使用Brotli compression压缩资源,使用以下命令
for i in dist/*; do brotli $i; done
。
*bundles默认生成到projectFolder/dist(/$projectFolder为6)。
使用Angular 8.2.11
与CLI 8.3.13
和选项CSS的大小,没有Angular路由。
dist/main-[es-version].[hash].js
你的应用程序捆绑在一起 [ES5大小:188 KB为新的Angular CLI应用程序空,44 KB压缩] 。dist/polyfill-[es-version].[hash].bundle.js
捆绑的polyfill依赖项(@angular, RxJS...) [ ES5大小:122 KB,用于新的Angular CLI应用程序,为空,36 KB压缩】。]dist/index.html
入口点。dist/runtime-[es-version].[hash].bundle.js
webpack loaderdist/style.[hash].bundle.css
样式定义。dist/assets
从Angular CLI资产配置中复制的资源你可以使用ng serve --prod
命令来预览你的应用程序,该命令启动了一个本地HTTP服务器,这样就可以使用http://localhost:4200 来访问带有生产文件的应用程序。
对于生产使用,你必须将dist
文件夹中的所有文件部署到你选择的HTTP服务器中。