简体   繁体   English

谷歌云 function 是否支持摇树?

[英]Does google cloud function supports tree shaking?

Will there be any difference in doing 1 or 2?做1或2会有什么不同吗?

1 1

import includes = require("lodash/includes");

export const isVeggie = functions.https.onCall((a, b) => includes(["potato", "tomato"], "onion"));

2 2

import _ = require("lodash");

export const isVeggie = functions.https.onCall((a, b) => _.includes(["potato", "tomato"], "onion"));

It isn't the responsibility of Cloud Functions to support or implement tree shaking. Cloud Functions 不负责支持或实现摇树。 It is just a runtime environment.它只是一个运行时环境。 It will dutifully run whatever you deploy to it.它会尽职尽责地运行你部署到它的任何东西。 It's up to you to add any sort of compilation, transpilation, or tree-shaking to your code build if you want that to happen prior to execution.如果您希望在执行之前发生这种情况,您可以在代码构建中添加任何类型的编译、转译或 tree-shaking。

From MSDN :来自MSDN

In modern JavaScript applications, we use module bundlers (eg, webpack or Rollup) to automatically remove dead code when bundling multiple JavaScript files into single files.在现代 JavaScript 应用程序中,我们使用模块捆绑器(例如,webpack 或 Rollup)在将多个 JavaScript 文件捆绑到单个文件时自动删除死代码。 This is important for preparing code that is production ready, for example with clean structures and minimal file size.这对于准备可用于生产的代码很重要,例如具有干净的结构和最小的文件大小。

So, if you are building to webpack or rollup properly configured for tree shaking, it will work fine and possibly minimize the amount of code that gets loaded at runtime.因此,如果您正在构建 webpack 或正确配置为摇树摇动的汇总,它将工作正常,并可能最大限度地减少运行时加载的代码量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM