首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当使用AsyncPipe : false时,摇动树的角度为10时将sideEffects抖出

当使用AsyncPipe : false时,摇动树的角度为10时将sideEffects抖出
EN

Stack Overflow用户
提问于 2020-06-28 01:39:50
回答 2查看 1.8K关注 0票数 7

摇动树的角度10是‘摇动’出我的AsyncPipe。

角10的发布笔记博客条目ng new引入了一种新的--strict模式

这样做的一件事是:

将您的应用程序配置为免费的副作用,以启用更高级的树抖动功能。

官方文件说:

当您使用严格模式创建项目和工作区时,您会注意到一个额外的package.json文件,位于src/app/目录中。此文件通知工具和绑定程序,此目录下的代码不存在非本地副作用。

这是那个package.json的内容

代码语言:javascript
复制
{
  "name": "heroes",
  "private": true,
  "description_1": "This is a special package.json file that is not used by package managers.",
  "description_2": "It is used to tell the tools and bundlers whether the code under this directory is free of code with non-local side-effect. Any code that does have non-local side-effects can't be well optimized (tree-shaken) and will result in unnecessary increased payload size.",
  "description_3": "It should be safe to set this option to 'false' for new applications, but existing code bases could be broken when built with the production config if the application code does contain non-local side-effects that the application depends on.",
  "description_4": "To learn more about this file see: https://angular.io/config/app-package-json.",
  "sideEffects": false
}

太棒了!我想。我喜欢更多的树摇动。

然而,它赶走了AsyncPipe,我不知道为什么。我在一个很大的网站上到处使用它--我不知道它怎么可能被优化掉。

它只在优化的--prod构建中这样做。当我把它改为sideEffects: true时,它又起作用了。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-08-06 12:07:47

这是一个角为10的已知臭虫艾薇的问题。当组件之间具有递归依赖关系时就会发生这种情况,例如AComponent imports BComponent,但是BComponent也导入AComponent

对于导入,重要的是生成的组件代码,而不是组件类的类型记录。这意味着在您的AComponent的模板中包含<app-b-component></app-b-component>也可以作为导入BComponent,因为在内部它引用了BComponent

因此,当前的工作,虽然仍然保持更积极的树摇动与sideEffects: false,将是消除所有递归导入。

票数 2
EN

Stack Overflow用户

发布于 2021-02-11 15:46:40

我只是遇到了这种“太大的树抖动”的问题,我的角度10应用程序和生产构建(使用optimization=true,这使树摇动的东西)。

在我的例子中,这是被破坏的DatePipe ({{value | date}})。

这会导致区域设置未定义的错误,而应该是错误的(如果在没有优化的情况下在开发模式下为应用提供服务也是可以的)

代码语言:javascript
复制
ERROR Error: InvalidPipeArgument: 'Missing locale data for the locale "fr".' for pipe 'e'

这里有更多详细信息:角"InvalidPipeArgument:缺少区域数据“在构建或与optimization=true一起使用时(--prod选项)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62617305

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档