Angular2应用dist包版本信息位置及构建后文件查询咨询
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.jsonfile, navigate toprojects -> [your-app-name] -> architect -> build -> options -> assets, and add"package.json"to the array. Next time you runng build --prod, thepackage.jsonfile will be copied directly to the root of yourdistfolder, 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 frompackage.jsonand inject it into your app's code. This way, it will also appear in the main bundle alongside yourenvironment.prod.tsversion.
内容的提问来源于stack exchange,提问作者Swpno

