javascript - Angular 7 使用 ng build --prod 缩小资产
问题描述
中的JavaScript 和 CSS 文件/assets
在ng build --prod
. 有人知道我可以如何缩小这些文件吗?我在角度文档中看不到任何内容。
解决方案
如果没有缩小,你在生产中构建的所有东西都已经缩小了我认为你没有在 angular.json 中打开配置。您可以在 angular.json 中使用这些配置
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": true,
"buildOptimizer": true,
"serviceWorker": true,
"deleteOutputPath": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
}
]
}
}
然后ng build --prod
再次运行
推荐阅读
- css - 带有偏移的CSS插入框阴影?
- ruby - 无法到达 binding.pry
- reactjs - React 路由器仅在刷新时显示组件
- angular - Ionic 4/ 5 - 当我再次访问同一个屏幕时删除缓存数据
- sql - 没有在 SQL 上的过程上打印
- html - 为什么此图像和 div 未对齐
- javascript - 尝试在我的项目中使用 Axios 时出现很多不同的错误
- python - 每当我的计时器对象被重置时,Tkinter after() 变得更快
- angular - 从 Angular 服务调用 AppSync 查询:如何将结果转换为 observable?
- python-3.x - 如何修复 macOS 中 Python2/3 的 ssl 错误