我们有一个SPFx网页部分项目,它呈现自适应卡-这个项目生成包使用Webpack通过吞咽-任务。
我们还有一个类型记录库(SPPacking库),它有很多实用函数。
|-- My-SPFx-Webpart
|-- package.json
|-- node_modules
|-- Common-Library
|--node_modules
|-- AdaptiveHtml implementing 'toJson'
|--Utils.ts file consuming node_module_1 as 'import AdaptiveHtml from "adaptive-html";当我们试图在webpart项目中设置TreeShaking时,我们得到了Cannot read property 'toJson' of undefined --我们相信库项目所使用的一个模块正在被抛弃,我们希望避免该模块(或消耗该模块的文件)的树抖动。
SPFX的所有文件都使用
Util。
在SPFx Webpart的json包中,有什么方法可以将Utils.ts标记为拥有sideEffects吗?
我们试过的东西,
package.json
{
"name": "My SPFx Webpart",
"sideEffects": [
"Common-Library", //tried to mark the whole node_module as sideEffect - not working
"Common-Library/Utils, //tried to mark the exported module as sideEffect - not working
"AdaptiveHtml", //tried to mark the exported affected node_module as sideEffect - not working
],请帮助我们在包json中将node_modules或子模块标记为sideEffect .
发布于 2022-10-05 18:58:55
我认为你必须指明整个路径。
这样做:
"sideEffects": ["./node_modules/Common-Library/Utils]https://stackoverflow.com/questions/73964231
复制相似问题