静态打字稿 class 方法树是否可以通过汇总摇动?
Are static typescript class methods tree shakeable by rollup?
假设我们用两个静态方法创建一个打字稿class:
export class Utilities {
static methodFoo() { return 'foo'}
static methodBoo() { return 'boo'}
}
后来有人从 npm 包 @scope/utilities
中导入我们的 class 并且只使用 methodFoo
这样的
import {Utilities} from '@scope/utilities';
let pityTheFoo = Utilities.methodFoo();
如果我们使用 rollup 将上面的内容发布为优化/'treeshaken' 模块,rollup 是否可以剃掉 methodBoo
?
截至 2019 年 11 月,不,静态方法未经过 treesaken。
Rollup Issue #349 was raised for it, where even the tool creator was sympathetic to having the feature. The issue closed in an auto-cleanup 由于自此之后不活动。
至于测试行为,您可以自己轻松完成:只需使用从未使用过的静态方法构建一个 class,使用 rollup.js(或 angular 或类似的东西包括汇总)并检查输出。
我正在为此苦苦挣扎,因为你将如何构建 treeshakable 实用程序?就像 rxjs 那样做,然后单独导出所有函数?然后你会失去所有的命名空间,这对我来说也不是理想的......我猜你的问题源于那个想法?
据我所知,您目前要么导出纯函数,要么您的实用程序不会被 treesaken。
假设我们用两个静态方法创建一个打字稿class:
export class Utilities {
static methodFoo() { return 'foo'}
static methodBoo() { return 'boo'}
}
后来有人从 npm 包 @scope/utilities
中导入我们的 class 并且只使用 methodFoo
这样的
import {Utilities} from '@scope/utilities';
let pityTheFoo = Utilities.methodFoo();
如果我们使用 rollup 将上面的内容发布为优化/'treeshaken' 模块,rollup 是否可以剃掉 methodBoo
?
截至 2019 年 11 月,不,静态方法未经过 treesaken。 Rollup Issue #349 was raised for it, where even the tool creator was sympathetic to having the feature. The issue closed in an auto-cleanup 由于自此之后不活动。
至于测试行为,您可以自己轻松完成:只需使用从未使用过的静态方法构建一个 class,使用 rollup.js(或 angular 或类似的东西包括汇总)并检查输出。
我正在为此苦苦挣扎,因为你将如何构建 treeshakable 实用程序?就像 rxjs 那样做,然后单独导出所有函数?然后你会失去所有的命名空间,这对我来说也不是理想的......我猜你的问题源于那个想法?
据我所知,您目前要么导出纯函数,要么您的实用程序不会被 treesaken。