1

我正在创建一个 WebExtension,我需要在我的 content.js 中使用选择菜单库。它有系绳依赖项,所以我安装了:

npm install tether
npm install selection-menu

然后在我的代码中我写:

import * as Tether from 'tether'
import SelectionMenu from 'selection-menu'

...
    this.selection_menu = new SelectionMenu({
      container: document.body,
      content: '<button> click me </button>',
      onselect: function(e) {
        this.menu.innerHTML = 'Selection length: ' + this.selectedText.length;
      }
    });

但是当我选择文本时,出现错误:

VM1492:23 Uncaught ReferenceError: Tether is not defined
    at i.show (<anonymous>:23:2899)
    at <anonymous>:23:4192

但在页面代码中我看到系绳已导入屏幕

如何解决此错误?

4

1 回答 1

0

这对我有用:

在我的 webpack.config.js 中:

config.plugins = (config.plugins || []).concat([
...
  new webpack.ProvidePlugin({
    tether: 'tether',
    Tether: 'tether',
    'window.Tether': 'tether',
  })
]);
于 2018-08-22T07:54:05.713 回答