gpt4 book ai didi

Webpack - mxClient 的加载程序,无法在导出中干净地加载所有相关对象

转载 作者:行者123 更新时间:2023-12-02 10:49:34 26 4
gpt4 key购买 nike

我当前的加载器是:

{
test: path.join(__dirname, '../libs/mxClient/js/mxClient.js'),
loaders: [
'exports?mxClient,mxGraph,mxGraphModel'
]
}

我似乎必须导出 mxClient 中存在的每个对象,以便在我使用时能够在我的应用程序中使用它:

var mxClientTest = require('mxClient');

另一个问题是,似乎当我尝试为我的模块使用 import 时,没有加载任何内容,但是当我将其分配给变量并使用 require 时,我确实得到了我在加载器中指定的导出,任何人都会知道为什么吗?

最佳答案

我已经能够通过 webpack 导入它。您必须在 module => Rules

下的 webpack 配置中添加以下代码
module: {
rules: [
...

{
test: require.resolve('mxgraph/javascript/mxClient'),
use: 'exports-loader?' +
'mxClient,mxLog,mxObjectIdentity,mxDictionary,mxResources,mxEffects,mxUtils,mxConstants,mxEvent,mxClipboard,mxUrlConverter,mxVmlCanvas2D,mxStencilRegistry,' +
'mxMarker,mxHierarchicalEdgeStyle,mxCellPath,mxPerimeter,mxEdgeStyle,mxStyleRegistry,mxCodecRegistry,mxGenericChangeCodec,mxStylesheetCodec,mxDefaultToolbarCodec,' +
'mxGraph,mxRubberband,mxHierarchicalLayout,mxFastOrganicLayout,mxGraphModel,mxPanningHandler,mxKeyHandler,mxParallelEdgeLayout,mxLayoutManager,mxCompactTreeLayout,' +
'mxPrintPreview,mxToolbar,mxOutline,mxCellTracker,mxCellOverlay,mxImage,mxLoadResources,mxPopupMenu,mxCylinder,mxRectangle,mxCellRenderer,mxVertexHandler,mxPoint,' +
'mxHandle,mxRhombus, mxActor,mxArrow,mxArrowConnector,mxCloud,mxConnector,mxConnector,mxEllipse,mxHexagon,mxImageShape,mxLabel,mxLine,mxPolyline,mxMarker,mxRectangleShape,' +
'mxShape,mxStencil,mxStencilRegistry,mxSwimlane,mxText,mxTriangle,mxAutoSaveManager,mxDivResizer,mxForm,mxGuide,mxImageBundle,mxImageExport,mxLog,mxMorphing,mxMouseEvent,' +
'mxPanningManager,mxSvgCanvas2D,mxUndoableEdit,mxUndoManager,mxUrlConverter,mxWindow,mxXmlCanvas2D,mxXmlRequest,mxCellEditor,mxCellState,mxCellStatePreview,mxConnectionConstraint,' +
'mxGraphSelectionModel,mxGraphView,mxMultiplicity,mxSwimlaneManager,mxTemporaryCellStates,mxGeometry,mxStackLayout,mxRadialTreeLayout,mxPartitionLayout,mxGraphLayout,' +
'mxEdgeLabelLayout,mxCompositeLayout,mxCircleLayout,mxSwimlaneOrdering,mxMinimumCycleRemover,mxMedianHybridCrossingReduction,mxHierarchicalLayoutStage,mxCoordinateAssignment,' +
'mxSwimlaneLayout,mxObjectCodec,mxGenericChangeCodec,mxTooltipHandler,mxSelectionCellsHandler,mxPopupMenuHandler,mxGraphHandler,mxElbowEdgeHandler,mxEdgeHandler,' +
'mxConstraintHandler,mxConnectionHandler,mxCellMarker,mxCellHighlight,mxDefaultPopupMenu,mxDefaultKeyHandler,mxCodec,mxGraphHierarchyModel,mxGraphAbstractHierarchyCell,' +
'mxGraphHierarchyEdge,mxGraphHierarchyNode,mxSwimlaneModel,mxEdgeSegmentHandler'
}
]
}

然后在代码中导入变量,如下所示:

import {
mxClient,
mxUtils,
mxConstants,
...
} from 'mxgraph/javascript/mxClient'

希望这有帮助:)

关于Webpack - mxClient 的加载程序,无法在导出中干净地加载所有相关对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38133164/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com