问题:之前项目未使用vite,使用的时webpack模式,所以joint画的模块在本地和线上是可以正常使用,项目更新未使用vite之后,就出现了问题
原因:由于项目中的流程节点需要自定义,所以在joint.shapes上自定义一个类型,如 joint.shapes.flow = {},接着在flow中增加我们的节点类型,本地是可以将flow属性增加到shapes上的,但是vite打包之后是无法添加上去,这个就是根本原因
原始代码
import * as joint from 'jointjs'; joint.shapes.flow = {}; export const fGeneral = (type, data) => { return joint.shapes.basic.Generic.extend({ markup: '<g class="rotatable"> <g class="inPorts"/><g class="outPorts"/> <g class="scalable"></g> <rect class="background"/> <rect class="color-band"/> <g class="icon"><image/></g> <text class="title"/> <text class="message"/> <g class="error"><image/></g> <g class="btn btn-code"><image/></g> </g> ', defaults: joint.util.defaultsDeep( { id: type, type: 'flow.Start', size: { 80, height: 54 }, attrs: {自已的定义}, ports: {自己的定义}, position: { x: data.posX, y: data.posY } }, joint.shapes.basic.Rect.prototype.defaults ), initialize: function() { joint.shapes.basic.Rect.prototype.initialize.apply(this, arguments); } }); };
joint.shapes.flow.Start= fGeneral();
export const createStart=(data)=>{
return new joint.shapes.flow.Start({});
};
在需要的位置,调用createStart方法
解决问题 - 根本是不挂载在shapes上
import * as joint from 'jointjs'; joint.shapes.flow = {}; export const fGeneral = (type, data) => { const result = joint.shapes.basic.Generic.extend({ markup: '<g class="rotatable"> <g class="inPorts"/><g class="outPorts"/> <g class="scalable"></g> <rect class="background"/> <rect class="color-band"/> <g class="icon"><image/></g> <text class="title"/> <text class="message"/> <g class="error"><image/></g> <g class="btn btn-code"><image/></g> </g> ', defaults: joint.util.defaultsDeep( { id: type, type: 'flow.Start', size: { 80, height: 54 }, attrs: {自已的定义}, ports: {自己的定义}, position: { x: data.posX, y: data.posY } }, joint.shapes.basic.Rect.prototype.defaults ), initialize: function() { joint.shapes.basic.Rect.prototype.initialize.apply(this, arguments); } }); return new result(); }; export const createStart=(data)=>{ return fGeneral("Start",data,""); }; 在需要的位置,调用createStart方法