我正在创建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
如何解决此错误?
答案 0 :(得分:0)
为我工作:
在我的webpack.config.js中:
config.plugins = (config.plugins || []).concat([
...
new webpack.ProvidePlugin({
tether: 'tether',
Tether: 'tether',
'window.Tether': 'tether',
})
]);