[英]webpack: Tether is not defined
I'm creating a WebExtension, I need to use the selection-menu library in my content.js. 我正在创建一个WebExtension,我需要在content.js中使用选择菜单库。 It has in tether dependencies, so I installed:
它具有系绳依赖性,因此我安装了:
npm install tether
npm install selection-menu
Then in my code I write: 然后在我的代码中写:
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;
}
});
but when I select text, I get an error: 但是当我选择文本时,出现错误:
VM1492:23 Uncaught ReferenceError: Tether is not defined
at i.show (<anonymous>:23:2899)
at <anonymous>:23:4192
but in the page code I see that tether was imported 但是在页面代码中,我看到系绳已导入
how to fix this error? 如何解决这个错误?
This work for me: 这项工作对我来说:
in my webpack.config.js: 在我的webpack.config.js中:
config.plugins = (config.plugins || []).concat([
...
new webpack.ProvidePlugin({
tether: 'tether',
Tether: 'tether',
'window.Tether': 'tether',
})
]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.