我们有一个SPFx Web部件项目,它渲染自适应卡-该项目通过gull任务使用Webpack生成捆绑包。
我们还有一个(ESM/esnext(类型脚本库(SPPack库(,它有很多实用功能。
|-- 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";
在Web部件项目中尝试设置TreeShaking时,我们得到了Cannot read property 'toJson' of undefined
我们相信库项目使用的一个模块正在被剥离,我们希望避免该模块(或消耗该模块的文件(的树抖动。
Utils用于SPFX Web部件的所有文件中。
在SPFxWebpart的包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。
我认为您必须指定整个路径。
这样做:
"sideEffects": ["./node_modules/Common-Library/Utils]