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

Angular2应用dist包版本信息位置及构建后文件查询咨询

Angular Production Build: Where to Find Version Info in the dist Folder

Great question! Let's walk through where you can locate your app's version details in the dist folder after running ng build --prod, based on your two configuration points:

1. Version from environment.prod.ts

When you build for production, Angular compiles your environment files directly into your app's main JavaScript bundle. You'll find this version string in:

  • dist/[your-app-name]/main.[unique-hash].js

Since production builds enable minification and hashing, the exact filename will change with each build (the [unique-hash] part is auto-generated). To find your version (0.0.0), open this file in a text editor and search for the version value—you'll spot it in a compressed format, usually something like "version":"0.0.0" embedded within the bundled code.

2. Version from package.json

By default, Angular doesn't automatically include the package.json file in the dist folder. If you want to access this version in your build output, you have two straightforward options:

  • Add it to your assets: Open your angular.json file, navigate to projects -> [your-app-name] -> architect -> build -> options -> assets, and add "package.json" to the array. Next time you run ng build --prod, the package.json file will be copied directly to the root of your dist folder, where you can view it directly.
  • Inject it into your code: You can use a custom webpack configuration (or Angular CLI's fileReplacements/environment variables) to pull the version from package.json and inject it into your app's code. This way, it will also appear in the main bundle alongside your environment.prod.ts version.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 08:19:53