我们使用AG网格。我想在导出React组件供使用之前添加我们的许可证,而不是每次使用网格组件时都要添加许可证。
我下面试过的都不管用。我认为,如果这样声明,副作用在进出口之前就会发生,但我的思维模式显然是错误的。我假设构建工具可能也会影响发生的事情,我们在这个特殊的情况下使用Gulp。
GridSupport.js (在设计包/回购中)
/**
* AG Grid License
*/
import { LicenseManager } from "@ag-grid-enterprise/core";
LicenseManager.setLicenseKey('…some license key…');
// Export below happens, but no license set above :(
export { AgGridReact as default } from "@ag-grid-community/react";Grid.js (另一个包/回购)
import { AgGridReact } from 'GridSupport';
const Grid = (props) => {
// AgGridReact should be usable without printing license warnings to the console
return <AgGridReact {...props} />
}我该怎么办呢?
发布于 2022-11-11 15:27:47
对这一问题进行了编辑,以澄清这两个文件在两个不同的包中。
我们开始在设计包/回购中将GridSupport.js添加到sideEffects中。这确保了许可证在出口发生前被正确地设置为副作用。
package.json
{
"name": "@ourcompany/design",
"sideEffects": [
"some/path/GridSupport.js"
],
"dependencies": [
"ag-grid-community": "...",
"ag-grid-enterprise": "...",
"ag-grid-react": "..."
]
}发布于 2022-11-10 17:13:26
为什么不在顶层(App.js或index.js)初始化许可证管理器?它将覆盖所有包含的网格。另外,请注意:在使用企业包时,请确保没有混合网格的包和模块。
https://stackoverflow.com/questions/74319722
复制相似问题