简体   繁体   中英

Does google cloud function supports tree shaking?

Will there be any difference in doing 1 or 2?

1

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

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

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. 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.

From 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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