javascript - React NPM 包(Dragula)在开发中有效,但在生产中无效

标签 javascript reactjs webpack dragula

我已经使用 React 15 和 Dragula 3.7.2 构建了一个不错的拖放功能,但是当我捆绑我的生产应用程序时,整个 dnd 都不起作用,除了我能够提升一个元素但是可以找个容器把它放进去。

我正在为我的容器分配对我当前在 componentDidMount 中创建的 drake 实例的引用。

我已将多个 EventListener 分配给 drake 实例,但唯一触发的是“拖动”-eventListener。我在那里控制台记录了 drake 实例,并看到我所有相关的容器都正确分配了

我还认为 dragula 包可能会出现缩小失败,所以我使用了来自 cdn 的版本

class ProcessGridDrag extends React.Component {
  constructor() {
    super();
    this.dragContext = null;
    this.dragContainers = [];
  }

  componentDidMount() {
    // eslint-disable-next-line no-undef
    this.drake = dragula(this.dragContainers, options);
    console.log('didMount');
    console.log(this.drake.containers);
    this.drake.on('drop', this.onDropTile);
    this.drake.on('out', this.onOutContainer);
    this.drake.on('over', console.log);
    this.drake.on('drag', () => {
      debugger;
      console.log(this.drake);
    });
    this.drake.on('shadow', console.log);
    // Override for touchmove for correct behaviour on iPad
    window.addEventListener('touchmove', () => {});
  }

  componentWillUnmount() {
    this.dragContainers = [];
    console.log('will Unmount');
    this.drake.containers = [];
    this.drake.off('drop', this.onDropTile);
    this.drake.off('out', this.onOutContainer);
    this.dragContext = null;
    this.drake.destroy();
  }
  
  // This one is passed down to components which should act as a drag container
  dragulaDecorator = componentBackingInstance => {
    if (
      componentBackingInstance &&
      this.dragContainers.indexOf(componentBackingInstance) === -1
    ) {
      this.dragContainers.push(componentBackingInstance);
    }
  };

webpack.config.prod: https://pastebin.com/BLu2hmmv webpack.config.dev: https://pastebin.com/3wczNisj

最佳答案

我的 CSS 有问题。我已经覆盖了被拖动元素的最高值。

由于生产中的 LoadOrder 不同,这个问题只发生在那里

关于javascript - React NPM 包(Dragula)在开发中有效,但在生产中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47014253/

相关文章:

javascript - 如何在每次点击移动图形时知道它的宽度和高度?

javascript - 当未设置显式值且字段包含任何字符时,Angular ng-maxlength 将字段标记为无效

reactjs - 如何使用 redux-form 进行受控输入?

node.js - docker webpack编译文件运行时丢失

javascript - Webpack 5 不显示图像

javascript - 定义 ES6 符号的简洁方法?

javascript - 如何在 Bokeh 的回调中使用 cb_obj?

reactjs - 错误 : [mobx] Computed values are not allowed to cause side effects by changing observables that are already being observed. 试图修改:

javascript - Reflux connectFilter 仍在向所有监听组件发送更新

reactjs - 如何确认 Tree Shaking 是否适用于 Webpack 2?